/**
 * Created by hcadmin on 16/9/30.
 */
$(function(){

    //$(window).scroll(function(event){
    //    console.log(event);
    //    $("input:focus").blur();
    //});



    var html;
    var greydiv             = "<div class='grey_div'></div>";
    var child_tag           = 0;
    var child_tag1          = 0;
    var child_tag_arr       = [];
    var approval_temp_id;
    var approval_copy       = "";
    var teamName            = "";
    //联系人全局  审批人  抄送人
    var contact_arr         = [];
    var contact_name_arr    = [];
    var contact_avatar_arr  = [];
    var contact_qyxBindId_arr=[];

    var contact_arr1        = [];
    var contact_name_arr1   = [];
    var contact_avatar_arr1 = [];
    var contact_qyxBindId_arr1 = [];

    var temp_arr            = [];
    var temp_name_arr       = [];
    var temp_avatar_arr     = [];
    var temp_qyxBindId_arr  = [];
    //设置多选框的变量
    var option_arr          = [];
    var option_str          = "";
    var title               = "";
    //存储有条件时候的审批人
    var localApprovals      = [];
    var component_id = "";
    //--类型  标题  append的div  灰色条  时间区间开始标题--结束标题  模板组件id  选项  是否必要
    function initComponents(type,title,placeholder,id,hadgreydiv,start_time_title,stop_time_title,component_id,options,necessary,default_value,extra_value,child_tag,date_type,parent_component_id,unit,component_blockletter,component_autoincrease,component_formatter,component_href){
        var right_img = "<img src='../../log/logImg/rightIcon.png' class='right_img'>";
        /*0：单行输入框 1：多行输入框 2：单选 3：多选 4：日期 5：时间区间 6：图片 7：明细 8：说明文字 9：金额 10：附件 13：数字输入框*/
        var need_text;
        var extra_text;
        var need;
        if(default_value!=""){
            need_text       = default_value;
        }else{
            if(necessary=='1'){
                need_text   ="请选择(必填)";
            }else{
                need_text   ='请选择';
            }
        }
        if(extra_value!=""){
            extra_text      = extra_value;
        }else{
            if(necessary=='1'){
                extra_text  = "请选择(必填)";
            }else{
                extra_text  = '请选择';
            }
        }
        if(necessary=="1"){
            need = "请选择(必填)";
            if(placeholder.indexOf('必填')<0){
                placeholder = placeholder + "(必填)";
            }
        }else{
            need = "请选择";
        }

        switch(type)
        {
            case 0:
                //if (title.length )

                html = "<div type='"+type+"' class='tableview_cell'><div class='Prompt_text_text'>"+title+"</div><input type='text' child_tag='"+child_tag+"' component_id='"+component_id+"' placeholder='"+placeholder+"' class='input_box default_value' necessary='"+necessary+"' title='"+title+"' value='"+default_value+"' style='width: 65vw'></div>";
                break;
            case 1:
                html = "<div type='"+type+"' class='tableview_cell multi_line'><div class='Prompt_text_input'>"+title+"</div><textarea style='margin-top: 0.9vh;height:12vh;line-height: 4vh' child_tag='"+child_tag+"' component_id='"+component_id+"' placeholder='"+placeholder+"' class='input_box multi_line_input_box default_value' necessary='"+necessary+"' title='"+title+"' style='resize:none;'>"+default_value+"</textarea></div>";
                break;
            case 2:
                html = "<div type='"+type+"' class='tableview_cell single_choice' component_id='"+component_id+"' data_primary='"+need+"' had_options='"+default_value+"' options='"+options+"'><div class='Prompt_text'>"+title+"</div><div class='show_val'><input type='button' child_tag='"+child_tag+"'  component_id='"+component_id+"' value='"+need_text+"' class='Prompt_text_right_time single_choice_val default_value' name='option' necessary='"+necessary+"' title='"+title+"'>"+right_img+"</div></div>";
                break;
            case 3:
                html = "<div type='"+type+"' class='multi_bigest'><div class='tableview_cell multi_choice' id='multi_choice"+component_id+"' data_primary='"+need+"' had_options='"+default_value+"' options='"+options+"' style='border:none'><div class='Prompt_text'>"+title+"</div><div class='show_val'><input type='button' child_tag='"+child_tag+"' component_id='"+component_id+"' value='"+need_text+"'  name='option' class='Prompt_text_right_time multi_choice_val default_value' necessary='"+necessary+"' title='"+title+"'>"+right_img+"</div></div></div>";
                break;
            case 4:
                html = "<div type='"+type+"' class='tableview_cell' data_primary='"+need+"'><div class='Prompt_text'>"+title+"</div><div class='show_val'><input type='button' child_tag='"+child_tag+"' component_id='"+component_id+"' name='time_component' value='"+need_text+"' id='choice_time"+component_id+"' class='Prompt_text_right_time choice_time default_value' necessary='"+necessary+"' title='"+title+"' date_type='"+date_type+"'>"+right_img+"</div></div>";
                break;
            case 5:

                var dateCal = "";
                var style = "";
                if (component_autoincrease == 1){
                    var day_unit = "";
                    if (date_type == 1){
                        //天
                        day_unit = "(天)";
                    }else {
                        //小时
                        day_unit = "(小时)";
                    }
                    dateCal = "<div class='during' name='date_"+ component_id +"'>时长"+ day_unit +":&nbsp;<span class='date_text' name='date_"+ component_id +"'></span></div>";
                }else {
                    style = "style='height:14.0625vh'";
                }





                html = "<div type='"+type+"' class='tableview_cell start_stop_time_bigest' data_primary='"+need+"' "+ style +"><div class='start_time_big'><div class='Prompt_text'>"+start_time_title+"</div><div class='show_val'><input child_tag='"+child_tag+"' type='button' component_id='"+component_id+"' name='time_component' interval='interval' value='"+need_text+"' id='start_time"+component_id+"' class='Prompt_text_right_time start_time default_value' necessary='"+necessary+"' title='"+start_time_title+"' date_type='"+date_type+"'>"+right_img+"</div></div><div class='stop_time_big'><div class='Prompt_text'>"+stop_time_title+"</div><div class='show_val'><input type='button' value='"+extra_text+"' title='"+stop_time_title+"' id='stop_time"+component_id+"' class='Prompt_text_right_time stop_time' date_type='"+date_type+"'>"+right_img+"</div></div>"+dateCal+"</div>";
                //html = html + dateCal;
                break;
            case 6:
                //图片
                var need_hint = "";
                if (necessary=='1'){
                    need_hint = "(必填)";
                }

                var html_img = "<form name='form' id='form' hidden><input type='file' name='img1'' class='upload' id='upload' multiple='multiple'></form>";
                html = "<div type='"+type+"' class='big_pic'><div class='tableview_cell_img'><div class='Prompt_text_file_image'>"+title+need_hint+"</div><div class='show_val_file_image'><img src='../approvalImg/pic.png' class='camera_pic'></div></div><div class='img_content default_value' necessary='"+necessary+"' title='"+title+"' name='img' child_tag='"+child_tag+"' component_id='"+component_id+"'>"+html_img+"</div>";
                break;
            case 7:
                if(edit=="1"){
                    html =
                        "<div type='"+type+"' name='detail_"+ component_id +"' class='detail_big'>" +
                            "<div name='detailContent_"+ component_id +"' class='detail_content'></div>" +
                            "<div class='tableview_cell_bottom' name='detailBottom_"+ component_id +"'>" +
                                "<div class='add_detail_text' div name='detailDetailText_"+ component_id +"'></div>" +
                            "</div>" +
                        "</div>" +
                        "<div class='grey_tips' name='greyTips_"+ component_id +"'></div>";
                }else{
                    html =
                        "<div type='"+type+"' name='detail_"+ component_id +"' class='detail_big'>" +
                            "<div name='detailContent_"+ component_id +"' class='detail_content'>" +
                                "<div name='detailReal_"+ component_id +"' class='detail_real' child_tag='"+ child_tag +"'>" +
                                    "<div name='detailText_"+ component_id +"' class='detail_text' child_tag='"+ child_tag +"'></div>" +
                                    "<div name='detailDeleteDiv_"+ component_id +"' class='detail_delete_div' child_tag='"+ child_tag +"'>" +
                                        "<img src='../approvalImg/delete.png' name='detailDelete_"+ component_id +"' class='detail_delete' child_tag='"+ child_tag +"'>" +
                                    "</div>" +
                                    "<div style='clear:both;'></div>" +
                                "</div>" +
                            "</div>" +
                            "<div name='detailBottom_"+ component_id +"' class='tableview_cell_bottom'>" +
                                "<div name='detailDetailText_"+ component_id +"' class='add_detail_text'></div>" +
                            "</div>" +
                        "</div>" +
                        "<div class='grey_tips' name='greyTips_"+ component_id +"'></div>";
                }
                break;
            case 8:
                html = "<div type='"+type+"' class='description_big'  component_href='"+ component_href + "'>"+title+"</div>";
                break;
            case 9:
                //console.log(unit);
                var unit_html = "";
                var input_box_style = "";
                //debugger;
                if (unit != undefined && unit.length > 0){
                    unit_html = "<div style='width: 20vw;height: 100%;line-height: 7.03125vh;font-size: 4.2vw;padding-right: 2.7vw;float: right;text-align: right'>" + unit + "</div>";
                    input_box_style = "style='float:left;'";
                }else {
                    //没有单位 input的样式
                    input_box_style = "style='width:65vw;float:left;'";
                }
                //height: 11.09375vh;
                //height: 7.03125vh;


                if(parent_component_id=="0"){
                    //e5e5e5
                    var cellStyle = "style='height:7.03125vh'";
                    var blocklatter_html = "";
                    if (component_blockletter == 1){
                        cellStyle = "style='height:11.09375vh'";
                        blocklatter_html = "<div class='cash_description_div' name='cashGrand_"+ component_id +"'>大写:&nbsp;<span class='capital_text' name='cashGrand_"+ component_id +"'></span></div>";
                    }

                    html =  "<div type='"+type+"' class='cash_big'"+cellStyle+">" +
                                "<div class='cash_content_big'>" +
                                    "<div class='Prompt_text_text'>"+title+"</div>" +
                                    "<input "+ input_box_style +" type='number' child_tag='"+child_tag+"' component_id='"+component_id+"' placeholder='"+ placeholder +"' class='input_box default_value num_input change_max_input' name='noparent' necessary='"+necessary+"' title='"+title+"' value='"+default_value+"'>" + unit_html +
                                "</div>" +
                                blocklatter_html +
                            "</div>";
                }else{
                    html = "<div type='"+type+"' class='cash_big' style='height: 7.03125vh'><div class='cash_content_big'><div class='Prompt_text_text'>"+title+"</div><input "+ input_box_style +" type='number' child_tag='"+child_tag+"' component_id='"+component_id+"' placeholder='"+ placeholder +"' class='input_box default_value num_input change_max_input' name='parent_"+ parent_component_id +"'  necessary='"+necessary+"' title='"+title+"' value='"+default_value+"'>" + unit_html +"</div></div>";

                    if (child_tag == 0) {
                        var blocklatter_html = "";
                        if (component_blockletter == 1){
                            blocklatter_html = "<div class='cash_description_div' name='cashGrand_"+ component_id +"'>大写:&nbsp;<span class='capital_text' name='cashGrand_"+ component_id +"'></span></div>";
                        }

                        var cashTotal =
                            "<div class='cash_description_div' name='cash_"+ component_id +"'>总"+ title  +":&nbsp;<span class='money_text' name='cash_"+ component_id +"'></span></div>"+ blocklatter_html;

                        $(".grey_tips[name='greyTips_"+ parent_component_id +"']").append(cashTotal);
                    }


                }
                break;
            case 10:
                //附件
                var need_hint = "";
                if (necessary=='1'){
                    need_hint = "(必填)";
                }
                var html_file = "<form name='form_file' id='form_file' hidden><input type='file' name='file' class='upload_file' id='upload_file' multiple='multiple'></form>";
                html = "<div type='"+type+"' class='big_file'><div class='tableview_cell_file'><div class='Prompt_text_file_image'>"+title+need_hint+"</div><div class='show_val_file_image'>"+html_file+"<img src='../approvalImg/file.png' class='file_pic'></div></div><div class='file_content default_value' necessary='"+necessary+"' title='"+title+"' name='file' child_tag='"+child_tag+"' component_id='"+component_id+"'></div></div>";
                break;
            case 13:
                var unit_html = "";
                var input_box_style = "";
                if (unit != undefined && unit.length > 0){
                    unit_html = "<div class='unit'>" + unit + "</div>";
                    input_box_style = "style='float:left;'";
                }else {
                    //没有单位 input的样式
                    input_box_style = "style='width:65vw;float:left;'";
                }


                if (parent_component_id != "0"){

                    if (unit.length > 0){
                        unit = "(" + unit + ")";
                    }

                    html = "<div type='"+type+"' class='tableview_cell'><div class='Prompt_text_text'>" + title + "</div><input type='number' child_tag='"+child_tag+"' component_id='"+component_id+"' placeholder='"+placeholder+"' class='input_box default_value num_input' name='parent_"+ parent_component_id +"' "+ input_box_style +" necessary='"+necessary+"' title='"+title+"' value='"+default_value+"'>"+ unit_html +"</div>";

                    if (child_tag == 0){
                        var numTotal = "<div class='cash_description_div' name='number_"+ component_id +"'>总"+ title  + unit +":&nbsp;<span class='money_text' name='number_"+ component_id +"'></span></div>";
                        $(".grey_tips[name='greyTips_"+ parent_component_id +"']").append(numTotal);
                    }

                }else {
                    html = "<div type='"+type+"' class='tableview_cell'><div class='Prompt_text_text'>" + title + "</div><input type='number' child_tag='"+child_tag+"' component_id='"+component_id+"' placeholder='"+placeholder+"' class='input_box default_value num_input' name='noparent' "+ input_box_style +" necessary='"+necessary+"' title='"+title+"' value='"+default_value+"'>"+ unit_html +"</div>";
                }
                break;
            default:
                break;
        }
        if(hadgreydiv=="1"){
            $("."+id+"").append(html,greydiv);
        }else{
            if(edit=="1"){
                $("."+id+"").last().append(html);
            }else{
                $("."+id+"").append(html);
            }
        }
    }


    function setTitleHeight(){

        $(".num_input").each(function(){
            $(this).css("margin-top","1.425vh");
            $(this).css("height","4vh");
            $(this).css("line-height","4vh");
        });

        $(".Prompt_text_text").each(function(){
            //console.log($(this).height());

            if ($(this).height() < 30){
                //单行
                $(this).css("line-height", "7.03125vh");

            }else {
                $(this).css("line-height", "3.5vh");


                //单行基准高度VH
                var singleLineHeight_vh = 7.03125;
                //判断单行基准高度
                var baseHeight = $(window).height() * singleLineHeight_vh / 100;


                if ($(this).height() > baseHeight){

                    var diffierent_distance = $(this).height() - baseHeight;

                    var diffierent_distance_vh_value = parseFloat(diffierent_distance) /parseFloat($(window).height()) * 100;
                    var final_height_value = diffierent_distance_vh_value + singleLineHeight_vh;
                    $(this).css("height", final_height_value + "vh");


                    //处理父级关系


                    var component = $(this).parent().parent();

                    if (component.attr("type") == "9") {
                        //金额
                        var component_height = component.height();

                        var final_height_value = component_height + diffierent_distance;
                        var final_height_vh_value = parseFloat(final_height_value) /parseFloat($(window).height()) * 100;
                        component.css("height", final_height_vh_value + "vh");


                        //处理大写情况
                        var lock_height = 4.0625;
                        var component_height_vh_value = parseFloat(component_height) /parseFloat($(window).height()) * 100;
                        if (component_height_vh_value > 8){
                            //有大写
                            final_height_vh_value = final_height_vh_value - lock_height + 0.1;
                        }

                        $(this).parent().css("height", final_height_vh_value + "vh");

                        var paddingTop = (final_height_vh_value - 4)/2;
                        $(this).next().css("margin-top", paddingTop + "vh");
                        $(this).next().css("height", 4 + "vh");
                        $(this).next().css("line-height",  "4vh");

                    }else {
                        component = $(this).parent();


                        if (component.attr("type") == "13" || component.attr("type") == "0"){
                            //数字
                            var component_height = component.height();

                            var final_height_value = component_height + diffierent_distance;
                            var final_height_vh_value = parseFloat(final_height_value) /parseFloat($(window).height()) * 100;
                            component.css("height", final_height_vh_value + "vh");

                            if (component.attr("type") == "0"){
                                $(this).next().css("height", final_height_vh_value - 0.2 + "vh");
                                $(this).next().css("line-height", final_height_vh_value - 0.2 + "vh");
                            }


                            if (component.attr("type") == "13"){
                                var paddingTop = (final_height_vh_value - 0.2 - 4)/2;

                                $(this).next().css("margin-top", paddingTop + "vh");
                                $(this).next().css("height",  4 + "vh");
                                $(this).next().css("line-height", "4vh");

                                //debugger;

                                if($(this).next().next().html().length > 0){
                                    //有单位 需要看单位的高度
                                    //var unit_current_height = $(this).next().next().height();
                                    //console.log(unit_current_height);




                                    $(this).next().next().css("line-height", /*final_height_vh_value - 0.2 + "vh"*/"4vh");

                                    var current_height = $(this).next().next().height();
                                    var current_height_vh = current_height/$(window).height() * 100;

                                    if (current_height_vh < final_height_vh_value - 0.2){
                                        var padding_top_vh = (final_height_vh_value - 0.2 - current_height_vh)/2;
                                        $(this).next().next().css("padding-top", padding_top_vh + "vh");
                                    }
                                    $(this).next().next().css("height", final_height_vh_value - 0.2 + "vh");
                                }
                                //else {
                                //    //没有单位
                                //
                                //}
                            }

                        }
                    }




                }
            }

        });
    }


    function unitDivHeight(){
        $(".unit").each(function(){
            var unit_current_height = $(this).height();
            var parent_height = $(this).parent().height();
            console.log(unit_current_height);
            console.log(parent_height);

            //2代表计算的误差
            if (unit_current_height - parent_height > 2){
                //需要换行了
                $(this).css("line-height","5vw");
                $(this).css("text-align","left");

                var new_unit_height = $(this).height();
                console.log(new_unit_height);

                if (new_unit_height > parent_height){
                    //撑开父级

                    $(this).parent().css("height",new_unit_height + "px");

                    var paddingTop = (new_unit_height - parent_height)/2;

                    //标题
                    $(this).parent().find(".Prompt_text_text").each(function(){
                        //var

                        $(this).css("padding-top",paddingTop + "px");
                    });

                    //输入框
                    $(this).parent().find(".num_input").each(function(){
                        var input_current_height = $(this).height();
                        var origin_padding_top = $(this).css('margin-top');



                        var true_heihgt = $(window).height() * 0.04;
                        var paddingTop = (new_unit_height - true_heihgt)/2;



                        $(this).css("margin-top",paddingTop + "px");
                        $(this).css("height", true_heihgt + "px");
                        $(this).css("line-height", "4vh");
                    });

                }else {
                    //行内调整
                    var paddingTop = (parent_height - new_unit_height)/2;
                    $(this).css("margin-top",paddingTop + "px");
                }

            }

        });
    }

    //获取url的参数
    (function ($) {
        $.getUrlParam = function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
    })(jQuery);
    var id          = $.getUrlParam('id');                 //模板的id
    var approval_id = $.getUrlParam('approval_id');        //审批的id
    var edit        = $.getUrlParam('edit');               //是否为  重新提交

    var temp_id = "";
    //获取模板,并且展示出来
    var url = apiurl+"/approvals/clienttemp/"+id+"";
    var data = {
        group_id : localStorage.group_id,
        user_id  : localStorage.user_id,
        token    : localStorage.token
    };

    $(document).on('focus','.input_box',function(e){


        //文本框所在的div
        var nav_height = $("#approval_navbar").outerHeight(true);


        //var documentHeight = $(".down_navbar_div").outerHeight(true) - nav_height;
            //$(window).height();
            //= $("#content").outerHeight(true) + $(".btnPublish").outerHeight(true);  //整个html高度
        //console.log(documentHeight);
        var windowHeight = $(window).height();  //屏幕高度

        //var content = document.getElementsByClassName('down_navbar_div');
        var current_top = $(document).scrollTop();
        //console.log("current_top:"+ current_top);

        var current_position_top = $(this).position().top;

        //console.log("position_top:"+ current_position_top);

        var distance_top = current_position_top - current_top;

        //console.log("distance_top:"+ distance_top);
//        var divHeight = $(".first-div").outerHeight(true) + $(".second-div").outerHeight(true) + $(".third-div").outerHeight(true); //键盘升起需要高于键盘的div总高度
//        var divHeight1 = $(".content_title").outerHeight(true) + $(".content_welcome").outerHeight(true) + $(this).parents('.content_question').outerHeight(true);
//        var divHeight2 = 0;
//        $(this).parents('.content_question').prevAll().each(function () {
//            divHeight2 += $(this).outerHeight(true);
//        });
//        var divHeight = divHeight1 + divHeight2;
//        console.log(divHeight);

        var keyboardHeight = windowHeight / 2;  //半屏
        //console.log("keyboardHeight:"+ keyboardHeight);

        //var halfWindowHeight = windowHeight / 2;

        var self_height = $(this).outerHeight(true);
        //console.log("self_height:"+ self_height);

        if (distance_top + self_height + keyboardHeight > windowHeight){
            //需要滚动
            var scroll_distance = distance_top + self_height + keyboardHeight - windowHeight;
            //console.log("scroll_distance:"+ scroll_distance);
            window.scrollTo(0, current_top + scroll_distance + nav_height);
        }
    });

    //$(document).on('onblur', '.desc', function (e) {
    //    $("#moreDiv").css('display', 'none');
    //});

    if(edit=="1"){
            //调用接口的URL
            var url_detail =apiurl+"/approvals/"+approval_id+"";
            $.ajax({
                beforeSend:function(){
                    $(".loading").show();
                },
                url:url_detail,
                data:{
                    user_id:localStorage.user_id,
                    token:localStorage.token
                },
                success:function(d){
                    if(typeof d == "object"){
                        var msg= d.msg;
                        if(msg=="202") {
                            $(".token_iframe").fadeIn(1000);
                        }
                    }
                    else
                    {
                        var call_back = JSON.parse(d);
                        var code      = call_back.code;
                        //console.log(call_back);
                        var data      = call_back.data;                                         //获取数据
                        var userInfo  = data.userCallbackString;                                //获取用户信息

                        if(code=="0"){
                            $(".loading").hide();

                            var approval_id         = data.approval_id;                              //审批id
                            var approval_model_name = data.approvalTemp.approval_title;              //使用模板的名称
                            var componentValue      = data.componentValue;                           //获取填写的值
                            var followers           = data.followers;                                //抄送人
                            var approvers           = data.approvers;
                            var followers_arr       = followers.split(",");
                            var approvers_arr       = approvers.split(",");
                            temp_id = data.approval_temp_id;

                            followers_arr.reverse();
                            approvers_arr.reverse();
                            //获取 模板
                            var approvalTemp        = data.approvalTemp;
                            var approval_title      = approvalTemp.approval_title;                    //模板的名称
                            title = approval_title;
                            approval_temp_id        = approvalTemp.approval_temp_id;                  //用于提交审批
                            var components          = approvalTemp.components;                        //模板的具体组件

                            $("#title").html(approval_title);                                         //模板名称显示title

                            //debugger;

                            //模板信息
                            for(var i=0;i<components.length;i++){
                                var component_type = components[i].component_type;
                                var component_title;
                                var component_placehold         = components[i].component_placehold;                //模板 placehold
                                var component_start_title       = components[i].component_start_title;              //开始时间 文字
                                var component_end_title         = components[i].component_end_title;                //结束时间 文字
                                var component_options           = components[i].component_options;                  //所有选项
                                var approval_temp_component_id  = components[i].approval_temp_component_id;         //模板组件的id
                                var is_necessary                = components[i].is_necessary;                       //是否 必要
                                var com_child                   = components[i].child;
                                var component_formatter         = components[i].component_formatter;
                                var component_actionname        = components[i].component_actionname;
                                var component_href        = components[i].component_href;
                                //单位
                                var component_unit       = components[i].component_unit;
                                //是否大小写
                                var component_blockletter       = components[i].component_blockletter;
                                //是否计算时长
                                var component_autoincrease = components[i].component_autoincrease;

                                if(component_type == "8"){
                                    component_title = components[i].component_dirction;
                                    var component_show = components[i].component_show;
                                    if (component_show == "1"){
                                        //判断是否显示在审批种
                                        initComponents(component_type, component_title, component_placehold, "down_navbar_div","0",component_start_title,component_end_title,approval_temp_component_id,component_options,is_necessary,"","","","","0",component_unit,component_blockletter,component_autoincrease,component_formatter,component_href);
                                    }
                                }else{
                                    component_title = components[i].component_title;
                                }

                                for(var j=0;j<componentValue.length;j++){
                                    var id            = componentValue[j].approval_temp_component_id;
                                    var value1        = componentValue[j].default_value;
                                    var value2        = componentValue[j].extra_value;
                                    var files         = componentValue[j].files;
                                    var child         = componentValue[j].child;
                                    var child_tag     = componentValue[j].child_tag;
                                    var default_value;
                                    var extra_value = "";
                                    var date_type                   = "0";

                                    if(component_formatter=="yyyy-MM-dd HH:mm"){
                                        date_type = "2"
                                    }else if(component_formatter=="yyyy-MM-dd"){
                                        date_type = "1";
                                    }else{
                                        date_type = "0";
                                    }

                                    if(approval_temp_component_id==id){
                                        if(component_type==3){
                                            initComponents(component_type, component_title, component_placehold, "down_navbar_div","1",component_start_title,component_end_title,approval_temp_component_id,component_options,is_necessary,value1,extra_value,child_tag,date_type,"0",component_unit,component_blockletter,component_autoincrease,component_formatter,component_href);
                                            if(value1!=""){
                                                var options_arr = [];
                                                options_arr = value1.split(",");
                                                for(var z=0;z<options_arr.length;z++){
                                                    if(z==0){
                                                        $($("#multi_choice"+approval_temp_component_id).find(".multi_choice_val")).val(options_arr[z]);
                                                        //$(".multi_choice_val").val(options_arr[z]);
                                                    }else{
                                                        $("#multi_choice"+approval_temp_component_id).parent().append("<div class='options_big'>"+options_arr[z]+"</div>");
                                                        //$(".multi_bigest").append("<div class='options_big'>"+options_arr[z]+"</div>");
                                                    }
                                                }
                                            }
                                        }else if(component_type==4){
                                            if(value1!=""){
                                                initDate(new Date(Math.round(value1)));
                                                if(component_formatter=="yyyy-MM-dd HH:mm"){
                                                    default_value = year_whole;

                                                }else{
                                                    default_value = year_mon_day;

                                                }
                                            }else{
                                                default_value = "";
                                            }

                                            initComponents(component_type, component_title, component_placehold, "down_navbar_div","1",component_start_title,component_end_title,approval_temp_component_id,component_options,is_necessary,default_value,extra_value,child_tag,date_type,"0",component_unit,component_blockletter,component_autoincrease,component_formatter,component_href);
                                            if(component_formatter=="yyyy-MM-dd HH:mm"){
                                                selectWholeDate($("#choice_time"+approval_temp_component_id));
                                            }else{
                                                selectDate($("#choice_time"+approval_temp_component_id));
                                            }
                                        }else if(component_type==5){
                                            if(value1!=""){
                                                initDate(new Date(Math.round(value1)));
                                                if(component_formatter=="yyyy-MM-dd HH:mm"){
                                                    default_value = year_whole;
                                                }else{
                                                    default_value = year_mon_day;
                                                }
                                            }else{
                                                default_value = "";
                                            }
                                            if(value2!=""){
                                                initDate(new Date(Math.round(value2)));
                                                if(component_formatter=="yyyy-MM-dd HH:mm"){
                                                    extra_value = year_whole;
                                                }else{
                                                    extra_value = year_mon_day;
                                                }
                                            }else{
                                                extra_value = "";
                                            }



                                            initComponents(component_type, component_title, component_placehold, "down_navbar_div","1",component_start_title,component_end_title,approval_temp_component_id,component_options,is_necessary,default_value,extra_value,child_tag,date_type,"0",component_unit,component_blockletter,component_autoincrease,component_formatter,component_href);
                                            if(component_formatter=="yyyy-MM-dd HH:mm"){
                                                selectWholeDate($("#stop_time"+approval_temp_component_id));
                                                selectWholeDate($("#start_time"+approval_temp_component_id));
                                            }else{
                                                selectDate($("#stop_time"+approval_temp_component_id));
                                                selectDate($("#start_time"+approval_temp_component_id));
                                            }
                                        }
                                        else if(component_type==6){
                                            initComponents(component_type, component_title, component_placehold, "down_navbar_div","1",component_start_title,component_end_title,approval_temp_component_id,component_options,is_necessary,value1,extra_value,child_tag,date_type,"0",component_unit,component_blockletter,component_autoincrease,component_formatter,component_href);
                                            if(value1!=""){
                                                var img_arr = value1.split(",");
                                                for(key in img_arr){
                                                    $(".img_content").append("<div class='pic_one'><img class='detail_approval_date_pic' src='"+img_arr[key]+"'><img src='../approvalImg/delete.png' class='delete_img'></div>");
                                                }
                                                if(img_arr.length==9){
                                                    $(".camera_pic").hide();
                                                }
                                            }
                                        }
                                        else if(component_type==7){
                                            initComponents(component_type, component_title, component_placehold, "down_navbar_div","1",component_start_title,component_end_title,approval_temp_component_id,component_options,is_necessary,value1,extra_value,child_tag,date_type,"0",component_unit,component_blockletter,component_autoincrease,component_formatter,component_href);

                                            //添加明显按钮文字
                                            if(component_actionname!=""){
                                                $(".add_detail_text[name='detailDetailText_"+ approval_temp_component_id +"']").html(component_actionname);
                                            }else{
                                                $(".add_detail_text[name='detailDetailText_"+ approval_temp_component_id +"']").html("增加明细");
                                            }

                                            if(child.length>0){
                                                //console.log(child);
                                                for(var m = 0; m < child.length; m++){
                                                    //var html1="";
                                                    //if(m = 0){
                                                    //    html1 = "<div class='detail_real' child_tag='"+child_tag+"'>" +
                                                    //        "<div class='detail_text' child_tag='"+child_tag+"'></div>" +
                                                    //        "<div class='detail_delete_div' child_tag='"+child_tag+"'><img src='../approvalImg/delete.png' class='detail_delete' child_tag='"+child_tag+"'></div>" +
                                                    //        "</div>";
                                                    //    $(".detail_content").append(html1);
                                                    //}else{
                                                    //}
                                                    //console.log(html1);


                                                    //html = "<div type='"+type+"' name='detail_"+ component_id +"' class='detail_big'>" +
                                                    //    "<div name='detailContent_"+ component_id +"' class='detail_content'>" +
                                                    //    "<div name='detailReal_"+ component_id +"' class='detail_real' child_tag='"+ child_tag +"'>" +
                                                    //    "<div name='detailText_"+ component_id +"' class='detail_text' child_tag='"+ child_tag +"'></div>" +
                                                    //    "<div name='detailDeleteDiv_"+ component_id +"' class='detail_delete_div' child_tag='"+ child_tag +"'>" +
                                                    //    "<img src='../approvalImg/delete.png' name='detailDelete_"+ component_id +"' class='detail_delete' child_tag='"+ child_tag +"'></div></div></div><div name='detailBottom_"+ component_id +"' class='tableview_cell_bottom'><div name='detailDetailText_"+ component_id +"' class='add_detail_text'></div></div></div><div class='grey_tips' name='greyTips_"+ component_id +"'></div>";

                                                    //console.log(approval_temp_component_id);

                                                    var html1 = "<div name='detailReal_"+ approval_temp_component_id +"' class='detail_real' child_tag='"+m+"'>" +
                                                                    "<div name='detailText_"+ approval_temp_component_id +"' class='detail_text' child_tag='"+m+"'></div>" +
                                                                    "<div name='detailDeleteDiv_"+ approval_temp_component_id +"' class='detail_delete_div' child_tag='"+m+"'><img src='../approvalImg/delete.png' class='detail_delete' child_tag='"+m+"'></div>" +
                                                                "</div>";
                                                    $(".detail_content[name='detailContent_"+ approval_temp_component_id +"']").append(html1);

                                                    if (m > 0){
                                                        $(".detail_delete_div[child_tag='"+ m +"']").show();
                                                    }

                                                    //



                                                    var child_c = child[m];
                                                    for (key1 in child_c) {
                                                        var id7             = child_c[key1].approval_temp_component_id;
                                                        var value17         = child_c[key1].default_value;
                                                        var value27         = child_c[key1].extra_value;
                                                        var files7          = child_c[key1].files;

                                                        var child_tag7      = child_c[key1].child_tag;
                                                        var default_value7;
                                                        var extra_value7    = "";




                                                        for (var dc = 0; dc < com_child.length; dc++) {
                                                            var component_typedc = com_child[dc].component_type;
                                                            var component_titledc;
                                                            var component_placeholddc = com_child[dc].component_placehold;                          //模板 placehold
                                                            var component_start_titledc = com_child[dc].component_start_title;                      //开始时间 文字
                                                            var component_end_titledc = com_child[dc].component_end_title;                          //结束时间 文字
                                                            var component_optionsdc = com_child[dc].component_options;                              //所有选项
                                                            var approval_temp_component_iddc = com_child[dc].approval_temp_component_id;            //模板组件的id
                                                            var is_necessarydc = com_child[dc].is_necessary;                                        //是否 必要
                                                            var component_formatterdc  = com_child[dc].component_formatter;
                                                            var parent_component_id = com_child[dc].parent_component_id;
                                                            var date_typedc = "0";
                                                            //var component_autoincreasec = com_child[dc].component_autoincrease;

                                                            var component_blockletterdc       = com_child[dc].component_blockletter;
                                                            var component_autoincreasedc      = com_child[dc].component_autoincrease;
                                                            var component_unitdc              = com_child[dc].component_unit;
                                                            var component_hrefc              = com_child[dc].component_href;
                                                            var component_showc             = com_child[dc].component_show;

                                                            if (component_typedc == "8") {
                                                                component_titledc = com_child[dc].component_dirction;
                                                                if (component_showc == "0"){
                                                                    continue;
                                                                }
                                                            } else {
                                                                component_titledc = com_child[dc].component_title;
                                                            }

                                                            if (approval_temp_component_iddc == id7) {

                                                                if(component_formatterdc=="yyyy-MM-dd HH:mm"){
                                                                    date_typedc  = "2";
                                                                }else if(component_formatterdc=="yyyy-MM-dd"){
                                                                    date_typedc  = "1";
                                                                }else{
                                                                    date_typedc = "0";
                                                                }

                                                                if (component_typedc == 3) {
                                                                    initComponents(component_typedc, component_titledc, component_placeholddc, "detail_real", "0", component_start_titledc, component_end_titledc, approval_temp_component_iddc, component_optionsdc, is_necessarydc, value17, extra_value7, child_tag7,date_typedc,parent_component_id,component_unitdc,component_blockletterdc,component_autoincreasedc,component_formatterdc,component_hrefc);
                                                                    if (value17 != "") {
                                                                        var options_arr7 = [];
                                                                        options_arr7 = value17.split(",");
                                                                        for (var z7 = 0; z7 < options_arr7.length; z7++) {
                                                                            if (z7 == 0) {
                                                                                $($("#multi_choice"+approval_temp_component_id).find(".multi_choice_val")).val(options_arr7[z7]);

                                                                                //$(".multi_choice_val").val(options_arr7[z7]);
                                                                            } else {
                                                                                $("#multi_choice"+approval_temp_component_id).parent().append("<div class='options_big'>"+options_arr7[z7]+"</div>");
                                                                                //$(".multi_bigest").append("<div class='options_big'>" + options_arr7[z7] + "</div>");
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                                else if (component_typedc == 4) {
                                                                    if (value17 != "") {
                                                                        initDate(new Date(Math.round(value17)));
                                                                        if(component_formatterdc=="yyyy-MM-dd HH:mm"){
                                                                            default_value7 = year_whole;

                                                                        }else{
                                                                            default_value7 = year_mon_day;

                                                                        }
                                                                    } else {
                                                                        default_value7 = "";
                                                                    }
                                                                    initComponents(component_typedc, component_titledc, component_placeholddc, "detail_real", "0", component_start_titledc, component_end_titledc, approval_temp_component_iddc, component_optionsdc, is_necessarydc, default_value7, extra_value7, child_tag7,date_typedc,parent_component_id,component_unitdc,component_blockletterdc,component_autoincreasedc,component_formatterdc,component_hrefc);
                                                                    if(component_formatterdc=="yyyy-MM-dd HH:mm"){
                                                                        selectWholeDate($("#choice_time"+approval_temp_component_iddc));
                                                                    }else{
                                                                        selectDate($("#choice_time"+approval_temp_component_iddc));
                                                                    }
                                                                }else if (component_typedc == 5) {
                                                                    if (value17 != "") {
                                                                        initDate(new Date(Math.round(value17)));
                                                                        if(component_formatterdc=="yyyy-MM-dd HH:mm"){
                                                                            default_value7 = year_whole;

                                                                        }else{
                                                                            default_value7 = year_mon_day;

                                                                        }
                                                                    } else {
                                                                        default_value7 = "";
                                                                    }
                                                                    if (value27 != "") {
                                                                        initDate(new Date(Math.round(value27)));
                                                                        if(component_formatterdc=="yyyy-MM-dd HH:mm"){
                                                                            extra_value7 = year_whole;

                                                                        }else{
                                                                            extra_value7 = year_mon_day;

                                                                        }
                                                                    } else {
                                                                        extra_value7 = "";
                                                                    }
                                                                    initComponents(component_typedc, component_titledc, component_placeholddc, "detail_real", "0", component_start_titledc, component_end_titledc, approval_temp_component_iddc, component_optionsdc, is_necessarydc, default_value7, extra_value7, child_tag7,date_typedc,parent_component_id,component_unitdc,component_blockletterdc,component_autoincreasedc,component_formatterdc,component_hrefc);
                                                                    if(component_formatterdc=="yyyy-MM-dd HH:mm"){
                                                                        selectWholeDate($("#start_time"+approval_temp_component_iddc));
                                                                        selectWholeDate($("#stop_time"+approval_temp_component_iddc));
                                                                    }else{
                                                                        selectDate($("#start_time"+approval_temp_component_iddc));
                                                                        selectDate($("#stop_time"+approval_temp_component_iddc));
                                                                    }
                                                                } else if (component_typedc == 6) {
                                                                    initComponents(component_typedc, component_titledc, component_placeholddc, "detail_real", "0", component_start_titledc, component_end_titledc, approval_temp_component_iddc, component_optionsdc, is_necessarydc, value17, extra_value7, child_tag7,date_typedc,parent_component_id,component_unitdc,component_blockletterdc,component_autoincreasedc,component_formatterdc,component_hrefc);
                                                                    if (value17 != "") {
                                                                        var img_arr7 = value17.split(",");
                                                                        for (key in img_arr7) {
                                                                            $(".img_content").append("<div class='pic_one'><img class='detail_approval_date_pic' src='" + img_arr7[key] + "'><img src='../approvalImg/delete.png' class='delete_img'></div>");
                                                                        }
                                                                        if(img_arr7.length==9){
                                                                            $(".camera_pic").hide();
                                                                        }
                                                                    }
                                                                } else if (component_typedc == 10) {
                                                                    initComponents(component_typedc, component_titledc, component_placeholddc, "detail_real", "0", component_start_titledc, component_end_titledc, approval_temp_component_iddc, component_optionsdc, is_necessarydc, value17, extra_value7, child_tag7,date_typedc,parent_component_id,component_unitdc,component_blockletterdc,component_autoincreasedc,component_formatterdc,component_hrefc);
                                                                    if (files7!=undefined&&files7!=null) {
                                                                        if(files7.length > 0) {
                                                                            for (key in files7) {
                                                                                var file_name7 = files7[key].file_name;
                                                                                var file_size7 = files7[key].file_size;
                                                                                var file_id7 = files7[key].file_id;
                                                                                //var file_id = data_url.file_id;
                                                                                var file_html7 = "<div class='file_real'>" +
                                                                                    "<div class='content_height' style='float: left;margin-left: 4vw;margin-right: 4vw'>" +
                                                                                    "<img src='../../approval/approvalImg/Giab/file_icon.png' class='file_img'></div>" +
                                                                                    "<div class='content_height' style='float: left;width: 70vw'>" +
                                                                                    "<div class='file_name' data-src='"+file_id7+"'>"+file_name7+"</div>" +
                                                                                    "<div class='file_size'>"+file_size7+"</div></div>" +
                                                                                    "<img src='../approvalImg/delete.png' class='file_delete'></div>";
                                                                                //$(_this_file).append(file_html);

                                                                                //if($($(_this_file).find(".file_img")).length>8){
                                                                                //    $(".call_back_success").html("最多上传9个附件").show().fadeOut(2000);
                                                                                //    $(".file_pic").hide();
                                                                                //}

                                                                                //var file_html7 = "<div class='file_real'>" +
                                                                                //    "<div class='col-xs-2 content_height'>" +
                                                                                //    "<img src='../../approval/approvalImg/word.png' class='file_img'></div>" +
                                                                                //    "<div class='col-xs-10 content_height'>" +
                                                                                //    "<p class='file_name' data-src='" + file_id7 + "'>" + file_name7 + "</p>" +
                                                                                //    "<p class='file_size'>" + file_size7 + "</p>" +
                                                                                //    "<img src='../approvalImg/delete.png' class='file_delete'></div></div>";
                                                                                $(".file_content").append(file_html7);
                                                                            }
                                                                        }
                                                                        if(files7.length==9){
                                                                            $(".file_pic").hide();
                                                                        }
                                                                    }
                                                                } else if (component_typedc=="9"){
                                                                    //金额
                                                                    //var unit = com_child[dc].component_unit;
                                                                    //var child_component_blockletter = com_child[dc].component_blockletter;

                                                                    initComponents(component_typedc, component_titledc, component_placeholddc, "detail_real", "0", component_start_titledc, component_end_titledc, approval_temp_component_iddc, component_optionsdc, is_necessarydc, value17, extra_value7, child_tag7,date_typedc,parent_component_id,component_unitdc,component_blockletterdc,component_autoincreasedc,component_formatterdc,component_hrefc);


                                                                    $(".change_max_input").bind('input',function(){
                                                                        var name_id = $(this).attr("component_id");

                                                                        var num = 0;
                                                                        $(".change_max_input[component_id='"+ name_id +"']").each(function(){
                                                                            var val = HTMLEncode($(this).val());
                                                                            if(val==""){
                                                                                val=0;
                                                                            }
                                                                            num += parseInt(val);

                                                                        });

                                                                        $(this).parent().parent().parent().parent().parent().next().find(".capital_text[name='cashGrand_"+ name_id +"']").html(convertCurrency(num));
                                                                        $(this).parent().parent().parent().parent().parent().next().find(".money_text[name='cash_"+ name_id +"']").html(num);
                                                                        val = 0;
                                                                    });

                                                                    //$(".change_max_input").unbind('input').bind('input',function(){
                                                                    //    var num = 0;
                                                                    //    $('.change_max_input').each(function(){
                                                                    //        var val = $(this).val();
                                                                    //        if(val==""){
                                                                    //            val=0;
                                                                    //        }
                                                                    //        num += parseInt(val);
                                                                    //    });
                                                                    //
                                                                    //    console.log(approval_temp_component_iddc);
                                                                    //    $(this).parent().parent().parent().parent().parent().next().find(".capital_text[name='cash_"+ approval_temp_component_iddc +"']").html(convertCurrency(num));
                                                                    //    $(this).parent().parent().parent().parent().parent().next().find(".money_text[name='cashGrand_"+ approval_temp_component_iddc +"']").html(num);
                                                                    //});
                                                                }else if (component_typedc=="13"){
                                                                    //数字
                                                                    //var unit = com_child[dc].component_unit;


                                                                    initComponents(component_typedc, component_titledc, component_placeholddc, "detail_real", "0", component_start_titledc, component_end_titledc, approval_temp_component_iddc, component_optionsdc, is_necessarydc, value17, extra_value7, child_tag7,date_typedc,parent_component_id,component_unitdc,component_blockletterdc,component_autoincreasedc,component_formatterdc,component_hrefc);

                                                                    $(".num_input").bind('input',function(){
                                                                        var name_id = $(this).attr("component_id");

                                                                        //console.log(name_id);

                                                                        var num = 0;
                                                                        $(".num_input[component_id='" + name_id +"']").each(function(){
                                                                            var val = HTMLEncode($(this).val());
                                                                            if(val==""){
                                                                                val=0;
                                                                            }
                                                                            num += parseInt(val);
                                                                        });

                                                                        $(this).parent().parent().parent().parent().next().find(".money_text[name='number_"+ name_id +"']").html(num);
                                                                        val = 0;
                                                                    });

                                                                }else {
                                                                    initComponents(component_typedc, component_titledc, component_placeholddc, "detail_real", "0", component_start_titledc, component_end_titledc, approval_temp_component_iddc, component_optionsdc, is_necessarydc, value17, extra_value7, child_tag7,date_typedc,parent_component_id,component_unitdc,component_blockletterdc,component_autoincreasedc,component_formatterdc,component_hrefc);
                                                                }

                                                            }

                                                        }
                                                    }
                                                }
                                            }


                                            if(component_title!=""){
                                                $(".detail_text[name='detailText_"+ approval_temp_component_id +"']").html(component_title);
                                            }else{
                                                $(".detail_text[name='detailText_"+ approval_temp_component_id +"']").html("明细");
                                            }



                                            //debugger;
                                            //统计
                                            //console.log($(".detail_big[name='detail_"+approval_temp_component_id+"']").next().attr("name"));

                                            var total_name = $(".detail_big[name='detail_"+approval_temp_component_id+"']").next().attr("name");
                                            var total_names = total_name.split("_");
                                            var name_id = total_names[1];

                                            var child_ids = [];
                                            $(".num_input[name='parent_"+ name_id +"']").each(function(){
                                                var child_id = $(this).attr("component_id");
                                                child_ids.push(child_id);
                                            });


                                            //去重
                                            var n = []; //一个新的临时数组
                                            for(var child_index = 0; child_index < child_ids.length; child_index++) //遍历当前数组
                                            {
                                                //如果当前数组的第i已经保存进了临时数组，那么跳过，
                                                //否则把当前项push到临时数组里面
                                                if (n.indexOf(child_ids[child_index]) == -1) n.push(child_ids[child_index]);
                                            }

                                            child_ids = n;

                                            //console.log(child_ids);

                                            for (var child_index = 0; child_index < child_ids.length; child_index++){
                                                var child_id = child_ids[child_index];

                                                var type = 0;
                                                var num = 0;
                                                $(".num_input[component_id='" + child_id +"']").each(function(){
                                                    var val = HTMLEncode($(this).val());
                                                    if(val==""){
                                                        val=0;
                                                    }
                                                    num += parseInt(val);

                                                    if ($(this).hasClass("change_max_input") == true){
                                                        type = 9;
                                                    }else {
                                                        type = 13;
                                                    }
                                                });
                                                //console.log(num);
                                                if (type == 9){
                                                    //金额
                                                    $(".capital_text[name='cashGrand_"+ child_id +"']").html(convertCurrency(num));
                                                    $(".money_text[name='cash_"+ child_id +"']").html(num);
                                                }else if(type == 13){
                                                    //数字
                                                    $(".money_text[name='number_"+ child_id +"']").html(num);
                                                }

                                                val = 0;

                                            }
                                            setDetailText(approval_temp_component_id);

                                        }
                                        else if(component_type==10){
                                            initComponents(component_type, component_title, component_placehold, "down_navbar_div","1",component_start_title,component_end_title,approval_temp_component_id,component_options,is_necessary,value1,extra_value,child_tag,date_type,"0",component_unit,component_blockletter,component_autoincrease,component_formatter,component_href);
                                            if(files!=undefined&&files!=null){
                                                if(files.length>0) {
                                                    for (key in files) {
                                                        var file_name = files[key].file_name;
                                                        var file_size = files[key].file_size;
                                                        var file_id = files[key].file_id;


                                                        //var file_id = data_url.file_id;
                                                        var file_html = "<div class='file_real'>" +
                                                            "<div class='content_height' style='float: left;margin-left: 4vw;margin-right: 4vw'>" +
                                                            "<img src='../../approval/approvalImg/Giab/file_icon.png' class='file_img'></div>" +
                                                            "<div class='content_height' style='float: left;width: 70vw'>" +
                                                            "<div class='file_name' data-src='"+file_id+"'>"+file_name+"</div>" +
                                                            "<div class='file_size'>"+file_size+"</div></div>" +
                                                            "<img src='../approvalImg/delete.png' class='file_delete'></div>";
                                                        //$(_this_file).append(file_html);
                                                        //
                                                        //if($($(_this_file).find(".file_img")).length>8){
                                                        //    $(".call_back_success").html("最多上传9个附件").show().fadeOut(2000);
                                                        //    $(".file_pic").hide();
                                                        //}
                                                        //var file_html = "<div class='file_real'>" +
                                                        //    "<div class='col-xs-2 content_height'>" +
                                                        //    "<img src='../../approval/approvalImg/word.png' class='file_img'></div>" +
                                                        //    "<div class='col-xs-10 content_height'>" +
                                                        //    "<p class='file_name' data-src='" + file_id + "'>" + file_name + "</p>" +
                                                        //    "<p class='file_size'>" + file_size + "</p>" +
                                                        //    "<img src='../approvalImg/delete.png' class='file_delete'></div></div>";
                                                        $(".file_content").append(file_html);
                                                    }
                                                }
                                                if(files.length==9){
                                                    $(".file_pic").hide();
                                                }
                                            }
                                        }
                                        else if(component_type==9){
                                            initComponents(component_type, component_title, component_placehold, "down_navbar_div","1",component_start_title,component_end_title,approval_temp_component_id,component_options,is_necessary,value1,extra_value,child_tag,date_type,"0",component_unit,component_blockletter,component_autoincrease,component_formatter,component_href);
                                            $(".change_max_input").bind('input',function(){
                                                var val = HTMLEncode($(this).val());
                                                $(this).parent().next().children(0).html(convertCurrency(val));
                                            });
                                        }
                                        else{
                                            initComponents(component_type, component_title, component_placehold, "down_navbar_div","1",component_start_title,component_end_title,approval_temp_component_id,component_options,is_necessary,value1,extra_value,child_tag,date_type,"0",component_unit,component_blockletter,component_autoincrease,component_formatter,component_href);
                                        }
                                    }
                                }

                            }

                            //审批人
                            var approval_html =
                                "<div class='copy_me'>" +
                                    "<div class='cope_me_up'><p class='person_text'>审批人</p>(点击头像可删除)</div>" +
                                    "<div class='copy_me_down' id='approval_person'>" +
                                        "<div class='copy_me_person_add' id='add_approval_person'>" +
                                            "<img src='../approvalImg/dotsAdd.png' class='add_person_img'>" +
                                        "</div>" +
                                    "</div>" +
                                "</div>";
                            var copy_html =
                                "<div class='copy_me'>" +
                                    "<div class='cope_me_up'><p class='person_text'>抄送人</p>(审批人同意后,将抄送给以下人员)</div>" +
                                    "<div class='copy_me_down' id='copy_person'>" +
                                        "<div class='copy_me_person_add' id='add_copy_person'>" +
                                            "<img src='../approvalImg/dotsAdd.png' class='add_person_img'>" +
                                        "</div>" +
                                    "</div>" +
                                "</div>";
                            $(".down_navbar_div").append(approval_html,copy_html);

                        }

                        //添加默认的审批人
                        getModel();


                        //设置时间周期
                        calDuringTime();

                        setTitleHeight();
                        unitDivHeight();
                    }

                }
            });


    }
    else{
        $.ajax({
            type:"GET",
            beforeSend:function(){
                $(".loading").show();
            },
            url:url,
            data:data,
            success:function(d){

                $(".loading").fadeOut(1,function(){
                    var data =JSON.parse(d).data;

                    var components = data.components;
                    approval_temp_id = data.approval_temp_id;
                    $("#title").html(data.approval_title);
                    title = data.approval_title;

                    var defaultApprovers = data.defaultApprovers;

                    //将默认审批人存到全局变量,用来添加
                    localApprovals = defaultApprovers;

                    //模板搭建
                    for(var i=0;i<components.length;i++) {
                        var component_type              = components[i].component_type;                     //模板类型
                        var component_title;
                        var component_placehold         = components[i].component_placehold;                //模板 placehold
                        var component_start_title       = components[i].component_start_title;              //开始时间 文字
                        var component_end_title         = components[i].component_end_title;                //结束时间 文字
                        var component_options           = components[i].component_options;                  //所有选项
                        var approval_temp_component_id  = components[i].approval_temp_component_id;         //模板组件的id
                        var is_necessary                = components[i].is_necessary;                       //是否 必要
                        var component_formatter         = components[i].component_formatter;
                        var component_actionname        = components[i].component_actionname;               //动作名称
                        var component_blockletter       = components[i].component_blockletter;
                        var component_autoincrease      = components[i].component_autoincrease;
                        var component_unit              = components[i].component_unit;
                        var component_href              = components[i].component_href;
                        var component_show              = components[i].component_show;


                        if(component_type == "8"){
                            //debugger;
                            component_title = components[i].component_dirction;
                            if (component_show == "0"){
                                //不显示在审批种
                                continue;
                            }
                        }else{
                            component_title = components[i].component_title;
                        }
                        var date_type                   = "0";
                        if(component_formatter=="yyyy-MM-dd HH:mm"){
                            date_type = "2"
                        }else if(component_formatter == "yyyy-MM-dd"){
                            date_type = "1"
                        }else{
                            date_type = "0";
                        }

                        if(component_type=="7"){
                            //html = "<div type='"+type+"' name='detail_"+ component_id +"' class='detail_big'>" +
                            //    "<div name='detailContent_"+ component_id +"' class='detail_content'>" +
                            //    "<div name='detailReal_"+ component_id +"' class='detail_real'>" +
                            //    "<div name='detailText_"+ component_id +"' class='detail_text'></div>" +
                            //    "<div name='detailDeleteDiv_"+ component_id +"' class='detail_delete_div'>" +
                            //    "<img src='../approvalImg/delete.png' name='detailDelete_"+ component_id +"' class='detail_delete'></div></div></div>" +
                            //    "<div name='detailBottom_"+ component_id +"' class='tableview_cell_bottom'>" +
                            //    "<div name='detailDetailText_"+ component_id +"' class='add_detail_text'></div></div></div>" +
                            //    "<div class='grey_tips' name='greyTips_"+ component_id +"'></div>";



                            //console.log(approval_temp_component_id);

                            initComponents(component_type, component_title, component_placehold, "down_navbar_div","1",component_start_title,component_end_title,approval_temp_component_id,component_options,is_necessary,"","","0",date_type,'0',component_unit,component_blockletter,component_autoincrease,component_formatter,component_href);
                            if(component_actionname!=""){
                                $(".add_detail_text[name='detailDetailText_"+ approval_temp_component_id +"']").html(component_actionname);
                            }else{
                                $(".add_detail_text[name='detailDetailText_"+ approval_temp_component_id +"']").html("增加明细");
                            }
                            if(component_title!=""){
                                $(".detail_text[name='detailText_"+ approval_temp_component_id +"']").html(component_title);
                            }else{
                                $(".detail_text[name='detailText_"+ approval_temp_component_id +"']").html("明细");
                            }
                            var component_child = components[i].child;
                            for(var j=0;j<component_child.length;j++){
                                var component_type7                 = component_child[j].component_type;
                                var component_title7;
                                var component_placehold7            = component_child[j].component_placehold;
                                var approval_temp_component_id7     = component_child[j].approval_temp_component_id;
                                var component_options7              = component_child[j].component_options;
                                var component_start_title7          = component_child[j].component_start_title;
                                var component_end_title7            = component_child[j].component_end_title;
                                var is_necessary7                   = component_child[j].is_necessary;
                                var component_formatter7            = component_child[j].component_formatter;
                                var parent_component_id             = component_child[j].parent_component_id;

                                var component_blockletter7       = component_child[j].component_blockletter;
                                var component_autoincrease7      = component_child[j].component_autoincrease;
                                var component_unit7              = component_child[j].component_unit;
                                var component_href7              = component_child[j].component_href;
                                var component_show7              = component_child[j].component_show;

                                if(component_type7 == "8"){
                                    component_title7 = component_child[j].component_dirction;
                                    if (component_show7 == "0"){
                                        continue;
                                    }
                                }else{
                                    component_title7 = component_child[j].component_title;
                                }
                                var date_type7;
                                if(component_formatter7=="yyyy-MM-dd HH:mm"){
                                    date_type7 = "2"
                                }else if(component_formatter7 == "yyyy-MM-dd"){
                                    date_type7 = "1"
                                }else{
                                    date_type7 = "0";
                                }
                                //var unit = "";
                                //var child_component_blockletter = "";
                                //if (component_type7 == 13 || component_type7 == 9){
                                //    unit = component_child[j].component_unit;
                                //    if (component_type7 == 9) {
                                //        child_component_blockletter = component_child[j].component_blockletter;
                                //    }
                                //}
                                //
                                //var child_component_autoincrease = component_child[j].component_autoincrease;
                                //console.log(child_component_blockletter);

                                initComponents(component_type7,component_title7,component_placehold7,"detail_real[name='detailReal_"+parent_component_id+"']","0",component_start_title7,component_end_title7,approval_temp_component_id7,component_options7,is_necessary7,"","","0",date_type7,parent_component_id,component_unit7,component_blockletter7,component_autoincrease7,component_formatter7,component_href7);
                                if(component_type7=="4"){
                                    if(component_formatter7=="yyyy-MM-dd HH:mm"){
                                        selectWholeDate($("#choice_time"+approval_temp_component_id7));
                                    }else{
                                        selectDate($("#choice_time"+approval_temp_component_id7));
                                    }
                                }
                                if(component_type7=="5"){
                                    if(component_formatter7=="yyyy-MM-dd HH:mm"){
                                        selectWholeDate($("#start_time"+approval_temp_component_id7));
                                        selectWholeDate($("#stop_time"+approval_temp_component_id7));
                                    }else{
                                        selectDate($("#start_time"+approval_temp_component_id7));
                                        selectDate($("#stop_time"+approval_temp_component_id7));
                                    }
                                }
                                if(component_type7=="9"){
                                    //金额
                                    $(".change_max_input").bind('input',function(){
                                        var name_id = $(this).attr("component_id");

                                        var num = 0;
                                        $(".change_max_input[component_id='"+ name_id +"']").each(function(){
                                            var val = HTMLEncode($(this).val());
                                            if(val==""){
                                                val=0;
                                            }
                                            num += parseInt(val);

                                        });

                                        $(this).parent().parent().parent().parent().parent().next().find(".capital_text[name='cashGrand_"+ name_id +"']").html(convertCurrency(num));
                                        $(this).parent().parent().parent().parent().parent().next().find(".money_text[name='cash_"+ name_id +"']").html(num);
                                        val = 0;
                                    });
                                }
                                if (component_type7 == "13"){
                                    //数字
                                    $(".num_input").bind('input',function(){
                                        var name_id = $(this).attr("component_id");

                                        var num = 0;
                                        $(".num_input[component_id='" + name_id +"']").each(function(){
                                            var val = HTMLEncode($(this).val());
                                            if(val==""){
                                                val=0;
                                            }
                                            num += parseInt(val);
                                        });

                                        $(this).parent().parent().parent().parent().next().find(".money_text[name='number_"+ name_id +"']").html(num);
                                        val = 0;
                                    });
                                }

                            }
                        }
                        else if(component_type=="9"||component_type=="8"){
                            var need_space = "1";
                            if (component_type == "8"){
                                need_space = "0";
                            }

                            //var unit = "";
                            //if (component_type == 9){
                            //    unit = components[i].component_unit;
                            //}
                            initComponents(component_type, component_title, component_placehold, "down_navbar_div",need_space,component_start_title,component_end_title,approval_temp_component_id,component_options,is_necessary,"","","0",date_type,"0",component_unit,component_blockletter,component_autoincrease,component_formatter,component_href);
                            $(".change_max_input[name='noparent']").bind('input',function(){
                                var val = HTMLEncode($(this).val());
                                $(this).parent().next().children(0).html(convertCurrency(val));
                            });
                        }
                        else{
                            //var unit = "";
                            //if (component_type == 13){
                            //    unit = components[i].component_unit;
                            //}
                            //var component_autoincrease = components[i].component_autoincrease;
                            initComponents(component_type, component_title, component_placehold, "down_navbar_div","1",component_start_title,component_end_title,approval_temp_component_id,component_options,is_necessary,"","","0",date_type,"0",component_unit,component_blockletter,component_autoincrease,component_formatter,component_href);
                            if(component_type=="4"){
                                if(component_formatter=="yyyy-MM-dd HH:mm"){
                                    selectWholeDate($("#choice_time"+approval_temp_component_id));
                                    date_type  = "2";
                                }else{
                                    selectDate($("#choice_time"+approval_temp_component_id));
                                    date_type  = "1";
                                }
                            }
                            if(component_type=="5"){
                                if(component_formatter=="yyyy-MM-dd HH:mm"){
                                    selectWholeDate($("#start_time"+approval_temp_component_id));
                                    selectWholeDate($("#stop_time"+approval_temp_component_id));
                                    date_type  = "2";
                                }else{
                                    selectDate($("#start_time"+approval_temp_component_id));
                                    selectDate($("#stop_time"+approval_temp_component_id));
                                    date_type  = "1";
                                }
                            }
                        }
                    }
                    //审批人,抄送人,提交
                    var approval_html = "";
                    approval_html = "<div class='copy_me'><div class='cope_me_up'><p class='person_text'>审批人</p>(点击头像可删除)</div><div class='copy_me_down' id='approval_person'><div class='copy_me_person_add' id='add_approval_person'><img src='../approvalImg/dotsAdd.png' class='add_person_img'></div></div></div>";
                    var copy_html = "<div class='copy_me'><div class='cope_me_up'><p class='person_text'>抄送人</p>(审批人同意后,将抄送给以下人员)</div><div class='copy_me_down' id='copy_person'><div class='copy_me_person_add' id='add_copy_person'><img src='../approvalImg/dotsAdd.png' class='add_person_img'></div></div></div>";
                    $(".down_navbar_div").append(approval_html,copy_html);
                    //默认审批人的时候
                    loadDefaultApproval(defaultApprovers);

                    setTitleHeight();
                    unitDivHeight();
                });
            }
        });
    }

    //进行添加默认的审批人的动作
    function addDefaultApproval(approvers,userLists){
        //审批人
        var dfas = approvers;
        var dfas_arr = dfas.split(",");
        //审批人详情
        var approvalList = userLists;

        var defaultCount = 0;

        for(var a in dfas_arr){
            var dfas_id;
            var apl_avatar;
            var apl_name;
            var apl_qyxBindId;
            for(var b in approvalList){
                var apl_id = approvalList[b].id;
                if(apl_id==dfas_arr[a]){
                    dfas_id = apl_id;
                    apl_avatar = approvalList[b].avatar;
                    apl_name = approvalList[b].name;
                    apl_qyxBindId = approvalList[b].qyxBindId;
                }
            }

            //if(apl_avatar==""){
                var color = avatar_getColor(apl_qyxBindId);
                img_src   = "<div class='cope_me_cover' style='background-color: "+color+"'>"+avatar_name(apl_name)+"</div>";
            //}else{
            if (apl_avatar.length > 0){
                var src = avatar_getUrl(localStorage.user_id,localStorage.token,apl_avatar);
                img_src += "<img src='"+src+"' class='cope_me_cover' hidden>";
            }

            //}

            var line = "";
            if (defaultCount < dfas_arr.length - 1){
                line = "<div class='dot_box'></div>";
            }

            $("#approval_person").append("<div class='copy_me_person_bigest'><div class='copy_me_person'>"+img_src+"<div class='approval_me_name' id='"+dfas_id+"' name='"+apl_name+"' avatar='"+apl_avatar+"' >"+apl_name+"</div></div>"+ line +"</div>");

            defaultCount ++;
        }
        showAvatar(".copy_me_person");
    }
    //根据defaultApprovers 判断是否要加载默认的审批人
    function loadDefaultApproval(defaultUsers){
        var defaultApprovers = defaultUsers;
        if(defaultApprovers!=undefined&&defaultApprovers.length>0){
            //隐藏选人按钮
            $("#add_approval_person").hide();

            var appType = defaultApprovers[0].type;    //0-不分条件  1-分条件
            var apl_component_id = defaultApprovers[0].approval_temp_component_id;
            var option_index = defaultApprovers[0].option_index;
            //判断  不分条件时候   区分条件时候的情况
            if(appType=="0"){
                addDefaultApproval(defaultApprovers[0].approvers,defaultApprovers[0].approverList);
            }
            //有条件的添加审批人  option_index==-1代表没有选项,判断输入框即可
            else{
                if(option_index=="-1"){

                    if(title.indexOf("报销")>-1){

                        $(".change_max_input").on("input propertychange",function(){
                            var plus = 0;
                            $(".change_max_input").each(function(){
                                //获取输入框的值
                                var value = $(this).val();
                                if(value==""){
                                    value = 0;
                                }else{
                                    value = parseInt(value);
                                }
                                plus+=value;
                            });

                            //循环  defaultApproval 进行比对
                            if($(this).attr('component_id')==apl_component_id){
                                if(plus==0){
                                    $('.copy_me_person_bigest').remove();
                                }else{
                                    for(var d in defaultApprovers){
                                        var lower_limit = defaultApprovers[d].lower_limit;
                                        var upper_limit = defaultApprovers[d].upper_limit;
                                        //判断数值在这个区间
                                        if(upper_limit==0&&lower_limit<plus){
                                            $('.copy_me_person_bigest').remove();
                                            addDefaultApproval(defaultApprovers[d].approvers,defaultApprovers[d].approverList);
                                        }
                                        if(plus>lower_limit&&plus<=upper_limit){
                                            $('.copy_me_person_bigest').remove();
                                            addDefaultApproval(defaultApprovers[d].approvers,defaultApprovers[d].approverList);
                                        }
                                    }
                                }
                            }
                        });
                    }else{
                        $(".input_box").each(function(){
                            $(this).on("input propertychange",function(){
                                //获取输入框的值
                                var value = HTMLEncode($(this).val());
                                //循环  defaultApproval 进行比对
                                if($(this).attr('component_id')==apl_component_id){
                                    if(value==""){
                                        $('.copy_me_person_bigest').remove();
                                    }else{
                                        value = parseInt(value);
                                        for(var d in defaultApprovers){
                                            var lower_limit = defaultApprovers[d].lower_limit;
                                            var upper_limit = defaultApprovers[d].upper_limit;
                                            //判断数值在这个区间
                                            if(upper_limit==0&&lower_limit<value){
                                                $('.copy_me_person_bigest').remove();
                                                addDefaultApproval(defaultApprovers[d].approvers,defaultApprovers[d].approverList);
                                            }
                                            if(value>lower_limit&&value<=upper_limit){
                                                $('.copy_me_person_bigest').remove();
                                                addDefaultApproval(defaultApprovers[d].approvers,defaultApprovers[d].approverList);
                                            }
                                        }
                                    }
                                }
                            });
                        })
                    }
                }
            }
        }
    }
    //编辑的时候,发送获取模板详情的请求,用来添加获取默认的审批人
    function getModel(){

        $.ajax({
            type:"GET",
            url:apiurl+"/approvals/clienttemp/"+temp_id+"",
            data:data,
            success:function(d){
                var data =JSON.parse(d).data;
                var defaultApprovers = data.defaultApprovers;
                localApprovals = defaultApprovers;

                loadDefaultApproval(defaultApprovers);
            }
        });
    }


    ////图片压缩
    //function compress(file){
    //    var image = new Image(),
    //        canvas = document.createElement("canvas"),
    //        ctx = canvas.getContext('2d');
    //
    //
    //    var reader = new FileReader();//读取客户端上的文件
    //    reader.onload = function() {
    //        var url = reader.result;//读取到的文件内容.这个属性只在读取操作完成之后才有效,并且数据的格式取决于读取操作是由哪个方法发起的.所以必须使用reader.onload，
    //        image.src=url;//reader读取的文件内容是base64,利用这个url就能实现上传前预览图片
    //    };
    //    image.onload = function() {
    //        var w = image.naturalWidth,
    //            h = image.naturalHeight;
    //        canvas.width = w;
    //        canvas.height = h;
    //        ctx.drawImage(image, 0, 0, w, h, 0, 0, w, h);
    //        //fileUpload();
    //    };
    //    reader.readAsDataURL(file);
    //
    //    var data = canvas.toDataURL("image/jpeg", 0.5);
    //    //dataURL 的格式为 “data:image/png;base64,****”,逗号之前都是一些说明性的文字，我们只需要逗号之后的就行了
    //    datadata = data.split(',')[1];
    //    data = window.atob(data);
    //    var ia = new Uint8Array(data.length);
    //    for (var i = 0; i < data.length; i++) {
    //        ia[i] = data.charCodeAt(i);
    //    }
    //    //canvas.toDataURL 返回的默认格式就是 image/png
    //    var blob = new Blob([ia], {
    //        type: "image/jpeg"
    //    });
    //    var fd = new FormData();
    //    fd.append('myFile', blob);
    //    return fd;
    //}

    //说明文字跳转
    $(document).on('click','.description_big',function(){
        var href = $(this).attr("component_href");
        if (href != null && href.length > 0){
            window.location= hrefComplex(href);
        }
    });

    //点击 图片
    //点击图片进行选择
    var _this_pic;
    $(document).on('click','.camera_pic',function(){
        _this_pic = $(this).parent().parent().next();
        $("#upload").click();

    });
    $(document).on('change','#upload',function(d){

        var formdata=new FormData($("#form")[0]);

        formdata.append("type","0");
        formdata.append("names", "img");


        var file = this.files[0];

        var file_name = file.name;

        var file_type = file.type;
        var type = file_type.split("/")[0];

        //var type = file_name.split(".")[1];
        if(checkImageType(file_name)==true) {
        //if(type=="image"){
            var lastImg;
            $.ajax({
                beforeSend:function(){
                    _this_pic.append("<div class='pic_one'><img class='detail_approval_date_pic' src='../approvalImg/loading.gif'><img src='../approvalImg/delete.png' class='delete_img'></div>");
                    lastImg = $(_this_pic.find(".detail_approval_date_pic")).last();
                },
                type : 'POST',
                url : apiurl+'/global/upload',
                data: formdata,
                cache : false,
                processData : false,
                contentType : false,
                mimeType:"multipart/form-data",
                success : function(d){
                    var data_url=JSON.parse(d).data;
                    lastImg.attr("src","http://"+data_url+"");
                    if($(_this_pic.find(".detail_approval_date_pic")).length>8){
                        $(".call_back_success").html("最多上传9张图片").show().fadeOut(2000);
                        var insert_button = $(_this_pic.parent().find(".camera_pic"));

                        $(insert_button).hide();
                    }
                }
            })
        }else {
            $(".call_back_success").html("不支持该图片类型!").fadeIn();
            setTimeout(function(){
                $(".call_back_success").fadeOut(1000);
            },1000);
        }
        var imgInput = $('#upload');
        imgInput.replaceWith(imgInput.val('').clone(true));
    });
    //-----移出图片
    $(document).on('click','.delete_img',function(){
       $(this).parent().remove();
        $(".camera_pic").show();
    });
    //点击 选择 附件
    var _this_file;
    $(document).on('click','.file_pic',function(){
        $("#upload_file").click();
        _this_file = $(this).parent().parent().next();
    });
    $(document).on('change','#upload_file',function(){
        //debugger;

        var formdata=new FormData($("#form_file")[0]);
        var file = this.files[0];
        if(file!=undefined){

            var file_size_k = file.size;
            var file_size;
            if(file_size_k<1000){
                file_size = Math.round(file_size_k) + "B";
            }else if(file_size_k<1000000){
                file_size = Math.round(file_size_k/1024) + "KB";
            }else{
                file_size = Math.round(file_size_k/1024/1024) + "MB";
            }
            var file_name = file.name;

            //类型
            var file_type = file.type;
            var type = file_type.split("/")[0];
            var imgSrc = "";
            if (type=="image"){
                imgSrc = "../../approval/approvalImg/Giab/file_icon.png";
            }else {
                imgSrc = "../../approval/approvalImg/word.png";
            }

            if (checkFileType(file_name) == true){
                formdata.append("type","1");
                formdata.append("file_size", file_size);
                $.ajax({
                    beforeSend:function(){
                        var html="<img src='../approvalImg/loading.gif' class='loading_file'>";
                        _this_file.append(html);
                    },
                    type : 'POST',
                    url : apiurl+'/global/singleUpload',
                    data: formdata,
                    cache : false,
                    processData : false,
                    contentType : false,
                    mimeType:"multipart/form-data",
                    success : function(d){
                        $(".loading_file").hide();
                        var data_url=JSON.parse(d).data;
                        var file_id = data_url.file_id;
                        var file_html = "<div class='file_real'>" +
                            "<div class='content_height' style='float: left;margin-left: 4vw;margin-right: 4vw'>" +
                            "<img src='"+ imgSrc +"' class='file_img'></div>" +
                            "<div class='content_height' style='float: left;width: 70vw'>" +
                            "<div class='file_name' data-src='"+file_id+"'>"+file_name+"</div>" +
                            "<div class='file_size'>"+file_size+"</div></div>" +
                            "<img src='../approvalImg/delete.png' class='file_delete'></div>";
                        _this_file.append(file_html);

                        if($(_this_file.find(".file_img")).length > 8){
                            $(".call_back_success").html("最多上传9个附件").show().fadeOut(2000);
                            var insert_button = $(_this_file.parent().find(".file_pic"));
                            $(insert_button).hide();
                        }
                    }
                });
            }else {
                $(".call_back_success").html("不支持该文件类型!").fadeIn();
                setTimeout(function(){
                    $(".call_back_success").fadeOut(1000);
                },1000);
            }
        }
        var fileInput = $('#upload_file');
        fileInput.replaceWith(fileInput.val('').clone(true));
    });
    //----删除附件
    $(document).on('click','.file_delete',function(){
       //console.log($(this).parent());
        $(this).parent().remove();
        $(".file_pic").show();
    });

    //点击 增加明细
    $(document).on('click','.add_detail_text',function(){


        var name =  $(this).attr("name");

        var nameSubstring = name.split("_");
        var component_id = nameSubstring[1];

        //console.log(component_id);

        var _this = $(".detail_real[name='detailReal_"+component_id+"']");


        var new_child = $(".detail_real[name='detailReal_"+component_id+"']:first").clone(true);
        //console.log(new_child);


        $(".detail_content[name='detailContent_"+component_id+"']").append(new_child);
        //
        //new_child.each(function(index){
        //    console.log($(this));
        //    //$(this).attr("child_tag",child_tag);
        //    $(this).attr("name","detailReal_"+ component_id + "_" + child_tag);
        //    child_tag++;
        //});



        //$(".detail_content").append($(".detail_real:first").clone(true));

        //清空最后一个明细的内容
        var child_length        = $(_this).last().children().length;

        //console.log($(_this).last());

        for(var i=0;i<child_length;i++){
            var this_con = $($(_this).last().children()[i]);
            var type = this_con.attr("type");

            if(type=="0"||type=="9"||type=="13"){
                $($(".detail_real[name='detailReal_"+component_id+"']").last().find(".input_box")).val("");
                $($(".detail_real[name='detailReal_"+component_id+"']").last().find(".capital_text")).html("");//0-单行 9-金额 13-数字

            }else if(type=="1"){
                $($(".detail_real[name='detailReal_"+component_id+"']").last().find('.input_box')).html("");                      //1-多行

            }else if(type=="2"){
                var text2 = $($(".detail_real[name='detailReal_"+component_id+"']").last().children()[i]).attr("data_primary");
                $($(".detail_real[name='detailReal_"+component_id+"']").last().children()[i]).attr("had_options","");                              //清空已经选择的值
                $($($(".detail_real[name='detailReal_"+component_id+"']").last().children()[i]).find('.single_choice_val')).val(text2);             //2-单选

            }else if(type=="3"){
                var text3 = $($(".detail_real").last().children()[i]).children(0).attr("data_primary");

                $($(".detail_real[name='detailReal_"+component_id+"']").last().children()[i]).attr("had_options","");                               //清空已经选择的值
                $($($(".detail_real[name='detailReal_"+component_id+"']").last().children()[i]).find('.multi_choice_val')).val(text3);             //3-多选
                //移除多选项
                if($($($(".detail_real[name='detailReal_"+component_id+"']").last().children()[i]).find('.options_big')).length>0){
                    $($($(".detail_real[name='detailReal_"+component_id+"']").last().children()[i]).find('.options_big')).remove();
                }

            }else if(type=="4"){
                var text4 = $($(".detail_real[name='detailReal_"+component_id+"']").last().children()[i]).attr("data_primary");

                $($($(".detail_real[name='detailReal_"+component_id+"']").last().children()[i]).find('.choice_time')).val(text4);                  //4-日期

            }else if(type=="5"){
                var text5 = $($(".detail_real[name='detailReal_"+component_id+"']").last().children()[i]).attr("data_primary");
                $($($(".detail_real[name='detailReal_"+component_id+"']").last().children()[i]).find('.start_time')).val(text5);
                $($($(".detail_real[name='detailReal_"+component_id+"']").last().children()[i]).find('.stop_time')).val(text5);
                $($($(".detail_real[name='detailReal_"+component_id+"']").last().children()[i]).find('.date_text')).html("");

            }else if(type=="6"){
                $($($(".detail_real[name='detailReal_"+component_id+"']").last().children()[i]).find('.pic_one')).remove();

            }else{
                $($($(".detail_real[name='detailReal_"+component_id+"']").last().children()[i]).find('.file_real')).remove();

            }
        }

        //后面添加的明细可以删除
        $(".detail_delete_div[name='detailDeleteDiv_"+component_id+"']").each(function(){
            $(this).show();
        }).first().hide();

        ////绑定时间事件
        //var type1,type2,type3;
        //type1 = $($(".detail_real[name='detailReal_"+component_id+"']").last().find(".choice_time")).attr("date_type");
        //type2 = $($(".detail_real[name='detailReal_"+component_id+"']").last().find(".start_time")).attr("date_type");
        //type3 = $($(".detail_real[name='detailReal_"+component_id+"']").last().find(".stop_time")).attr("date_type");
        //var id1,id2,id3;
        //id1 = $($(".detail_real[name='detailReal_"+component_id+"']").last().find(".choice_time")).attr("id");
        //id2 = $($(".detail_real[name='detailReal_"+component_id+"']").last().find(".start_time")).attr("id");
        //id3 = $($(".detail_real[name='detailReal_"+component_id+"']").last().find(".stop_time")).attr("id");
        //
        //
        ////console
        //console.log(id1);
        //console.log(id2);
        //console.log(id3);
        //
        //if(type1=="1"){
        //    selectDate($("#"+id1));
        //}else{
        //    selectWholeDate($("#"+id1));
        //}
        //if(type2=="1"){
        //    selectDate($("#"+id2));
        //}else{
        //    selectWholeDate($("#"+id2));
        //}
        //if(type3=="1"){
        //    selectDate($("#"+id3));
        //}else{
        //    selectWholeDate($("#"+id3));
        //}

        //var type1,type2,type3;
        //var id1,id2,id3;
        $($(".detail_real[name='detailReal_"+component_id+"']").last()).each(function(){
            $($(this).find(".choice_time")).each (function(){

                //console.log($(this));

                var type = $(this).attr("date_type");
                //id1 = $(this).attr("id");

                if(type=="1"){
                    selectDate($(this));
                }else{
                    selectWholeDate($(this));
                }

            });
            $($(this).find(".start_time")).each (function(){
                var type = $(this).attr("date_type");
                //id2 = $(this).attr("id");

                if(type=="1"){
                    selectDate($(this));
                }else{
                    selectWholeDate($(this));
                }
            });
            $($(this).find(".stop_time")).each (function(){
                var type = $(this).attr("date_type");
                //id3 = $(this).attr("id");
                if(type=="1"){
                    selectDate($(this));
                }else{
                    selectWholeDate($(this));
                }
            });
        });





        //debugger;
        $(".detail_real[name='detailReal_"+component_id+"']").each(function(index){
            $(this).attr("child_tag",child_tag);
            child_tag++;
        });
        child_tag=0;
        $(".detail_text[name='detailText_"+component_id+"']").each(function(index){
            $(this).attr("child_tag",child_tag);
            child_tag++;
        });
        child_tag=0;
        $(".detail_delete_div[name='detailDeleteDiv_"+component_id+"']").each(function(index){
            $(this).attr("child_tag",child_tag);
            child_tag++;
        });
        child_tag=0;
        $(".detail_delete[name='detailDelete_"+component_id+"']").each(function(index){
            $(this).attr("child_tag",child_tag);
            child_tag++;
        });
        child_tag=0;

        //更新编号
        //console.log(component_id);
        setDetailText(component_id);


        //var a;
        //
        //$(".change_max_input").unbind('input').bind('input',function(){
        //    var num = 0;
        //    $('.change_max_input').each(function(){
        //        var val = $(this).val();
        //        if(val==""){
        //            val=0;
        //        }
        //        num += parseInt(val);
        //    });
        //    a = num;
        //    $(this).parent().parent().parent().parent().parent().next().find('.capital_text').html(convertCurrency(num));
        //    $(this).parent().parent().parent().parent().parent().next().find('.money_text').html(num);
        //});


        //$(".change_max_input").each(function(){
        //    $(this).on("input propertychange",function(){
        //        //var plus=0;
        //        ////获取输入框的值
        //        //var value = $(this).val();
        //        //if(value==""){
        //        //    value = 0;
        //        //}else{
        //        //    value = parseInt(value);
        //        //}
        //        //plus+=value;
        //        //
        //        //console.log(plus);
        //
        //        //循环  defaultApproval 进行比对
        //        //if($(this).attr('component_id')==apl_component_id){
        //            if(a==0){
        //                $('.copy_me_person_bigest').remove();
        //            }else{
        //                for(var d in localApprovals){
        //                    var lower_limit = localApprovals[d].lower_limit;
        //                    var upper_limit = localApprovals[d].upper_limit;
        //                    //判断数值在这个区间
        //                    if(upper_limit==0&&lower_limit<a){
        //                        $('.copy_me_person_bigest').remove();
        //                        addDefaultApproval(localApprovals[d].approvers,localApprovals[d].approverList);
        //                    }
        //                    if(a>lower_limit&&a<=upper_limit){
        //                        $('.copy_me_person_bigest').remove();
        //                        addDefaultApproval(localApprovals[d].approvers,localApprovals[d].approverList);
        //                    }
        //                }
        //            }
        //        //}
        //    });
        //})
    });


    function setDetailText(approval_temp_component_id){
        var count = $(".detail_text[name='detailText_"+approval_temp_component_id+"']").length;


        $(".detail_text[name='detailText_"+approval_temp_component_id+"']").each(function(index){
            var name = $(this).html();

            var nameList = name.split("-");
            var prename = nameList[0];
            if (count > 1){
                var number = index + 1;
                prename = prename + "-" + number;
            }
            //console.log(prename);
            $(this).html(prename);
        });
    }


    $(document).on('click','.detail_delete_div',function(){
        $(this).parent().remove();
        //重算金额
        var total_name = $(this).parent().attr("name");
        var total_names = total_name.split("_");
        var name_id = total_names[1];

        var child_ids = [];
        $(".num_input[name='parent_"+ name_id +"']").each(function(){
            var child_id = $(this).attr("component_id");
            child_ids.push(child_id);
        });


        //去重
        var n = []; //一个新的临时数组
        for(var i = 0; i < child_ids.length; i++) //遍历当前数组
        {
            //如果当前数组的第i已经保存进了临时数组，那么跳过，
            //否则把当前项push到临时数组里面
            if (n.indexOf(child_ids[i]) == -1) n.push(child_ids[i]);
        }

        child_ids = n;

        //console.log(child_ids);

        for (var i = 0; i < child_ids.length; i++){
            var child_id = child_ids[i];

            var type = 0;
            var num = 0;
            $(".num_input[component_id='" + child_id +"']").each(function(){
                var val = HTMLEncode($(this).val());
                if(val==""){
                    val=0;
                }
                num += parseInt(val);

                if ($(this).hasClass("change_max_input") == true){
                    type = 9;
                }else {
                    type = 13;
                }
            });

            if (type == 9){
                //金额
                $(".capital_text[name='cashGrand_"+ child_id +"']").html(convertCurrency(num));
                $(".money_text[name='cash_"+ child_id +"']").html(num);
            }else if(type == 13){
                //数字
                $(".money_text[name='number_"+ child_id +"']").html(num);
            }

            val = 0;

        }


        setDetailText(name_id);

    });

    //点击选择时间
    //-----选择开始时间
    //选择全部时间
    function selectWholeDate(obj) {
        var currYear = (new Date()).getFullYear();
        var opt = {};
        opt.date = { preset: 'date' };
        opt.datetime = { preset: 'datetime' };
        opt.time = { preset: 'time' };
        opt.default = {
            theme: 'sense-ui', //皮肤样式
            display: 'modal', //显示方式
            mode: 'scroller', //日期选择模式
            lang: 'zh',
            startYear: currYear - 10, //开始年份
            endYear: currYear + 10 //结束年份


        };
        var optDateTime = $.extend(opt['datetime'], opt['default']);
        obj.mobiscroll(optDateTime).datetime(optDateTime);

        //console.log(optDateTime);
    }
    //--选择 日期
    function selectDate(obj) {

        //console.log(obj);

        var currYear = (new Date()).getFullYear();
        var opt = {};
        opt.date = { preset: 'date' };
        opt.datetime = { preset: 'datetime' };
        opt.time = { preset: 'time' };
        opt.default = {
            theme: 'sense-ui', //皮肤样式
            display: 'modal', //显示方式
            mode: 'scroller', //日期选择模式
            lang: 'zh',
            startYear: currYear - 10, //开始年份
            endYear: currYear + 10 //结束年份


        };
        var optDateTime = $.extend(opt['datetime'], opt['default']);
        obj.mobiscroll(optDateTime).date(optDateTime);

        //console.log(optDateTime);
        initTimestamp(HTMLEncode(obj.val()));
        default_value = timestamp;
    }


    $(document).on('change','.Prompt_text_right_time',function(){
        //console.log($(this).parent().parent().parent().attr("type"));
        if ($(this).parent().parent().parent().attr("type") == "5"){


            var date_type = $(this).attr("date_type");
            //debugger;

            var _start_time = HTMLEncode($($(this).parent().parent().parent().find(".start_time")).val());
            var _end_time = HTMLEncode($($(this).parent().parent().parent().find(".stop_time")).val());

            var start_timestamp = dateStringToTimestamp(_start_time,date_type);
            var end_timestamp = dateStringToTimestamp(_end_time,date_type);

            var during = (end_timestamp - start_timestamp)/1000;


            var time = 0;
            if (during != NaN && during > 0){
                if (date_type == 1){
                    //天
                    time = parseInt(during/86400);
                    time = time + 1;
                }else {
                    //小时
                    time = parseInt(during/3600);

                    var remain = during%3600;
                    //超过半天计0.5
                    if (remain >= 1800){
                        time = time + 0.5;
                    }
                }
                $($(this).parent().parent().parent().find(".date_text")).html(time);
            }else if (during == 0){
                if (date_type == 1){
                    //天
                    time = 1;
                    $($(this).parent().parent().parent().find(".date_text")).html(time);
                }
            }
        }

    });

    function calDuringTime(){
        $(".tableview_cell[type='5']").each(function(){

            var date_type = $($(this).find(".start_time")).attr("date_type");

            var _start_time = HTMLEncode($($(this).find(".start_time")).val());
            var _end_time = HTMLEncode($($(this).find(".stop_time")).val());

            var start_timestamp = dateStringToTimestamp(_start_time);
            var end_timestamp = dateStringToTimestamp(_end_time);

            var during = (end_timestamp - start_timestamp)/1000;



            var time = 0;
            if (during != NaN && during > 0){

                if (date_type == 1){
                    //天
                    time = parseInt(during/86400);
                    time = time + 1;
                }else {
                    //小时
                    time = parseInt(during/3600);

                    var remain = during%3600;
                    //超过半天计0.5
                    if (remain >= 1800){
                        time = time + 0.5;
                    }
                }
                $($(this).parent().parent().parent().find(".date_text")).html(time);
            }else if (during == 0){
                if (date_type == 1){
                    //天
                    time = 1;
                    $($(this).parent().parent().parent().find(".date_text")).html(time);
                }
            }

            //if (during != NaN && during > 0){
            //
            //    var time = 0;
            //    if (date_type == 1){
            //        //天
            //        time = parseInt(during/86400);
            //    }else {
            //        //小时
            //        time = parseFloat(during/3600.0);
            //    }
            //
            //    ////计算天数
            //    ////var timediff = $endtime-$starttime;
            //    //var days = parseInt(during/86400);
            //    ////计算小时数
            //    //var remain = during%86400;
            //    //var hours = parseInt(remain/3600);
            //    ////计算分钟数
            //    //remain = remain%3600;
            //    //var mins = parseInt(remain/60);
            //    ////计算秒数
            //    //var secs = remain%60;
            //    //
            //    ////console.log(days + "  " + hours + "  " + mins + "  " + secs);
            //
            //    $($(this).find(".date_text")).html(time + "天");
            //}

        })
    }

    function dateStringToTimestamp(dateString,date_type){
        if (date_type == "1"){
            dateString = dateString + " 00:00:00";
        }

        var time = new Date(Date.parse(new Date(dateString)));

        return time.getTime();
    }

    //点击弹出 单选
    var _single_this;
    $(document).on('click','.single_choice',function(){
        _single_this = $(this);
        var options_str = $(this).attr("options");
        component_id = $(this).attr("component_id");
        var options_arr = [];
        options_arr = options_str.split(",");
        $(".more_again").append("<div class='popup_similar'>" +
            "<div class='real_popup_content_single' index='-1'>"+
            "<div class='option_content col-xs-9'>请选择</div>" +
            "</div></div>");
        for(var i=0;i<options_arr.length;i++){
            $(".more_again").append("<div class='popup_similar'>" +
                "<div class='real_popup_content_single' index='"+i+"'>"+
                "<div class='option_content col-xs-9' style='max-line-height: 5vw'>"+options_arr[i]+"</div>" +
                "<div class='col-xs-3'><img src='../approvalImg/unchoice_round.png' class='choice_round_img'></div>"+
                "</div></div>");
        }
        var had_options = $(this).attr("had_options");
        if(had_options!="null"){
            $(".option_content").each(function(){
                if(had_options==$(this).html()){
                    $(this).next().children(0).attr("src","../approvalImg/choice_round.png")
                }
            });
        }

        var cellWhole  = 7.8125 * (options_arr.length + 2);

        if(cellWhole>52){
            $(".more_again").css("marginTop",'23.95vh');
        }else{
            var top        = (100 - cellWhole)/2 + "vh";
            $(".more_again").css("marginTop",top);
        }
        $(".more_again").append("<div class='popup_similar'>" +
            "<div class='single_cancel choice_it cancel'>取消"+
            "</div></div>");
       $(".call_back").show();

        //页面不可滚
        $('.body_bgcolor').css('overflow','hidden');
    });
    //---点击 选项
    $(document).on('click','.real_popup_content_single',function(){
        if ($(this).attr("index") == "-1"){
            return;
        }
        $(".choice_round_img").attr("src","../approvalImg/unchoice_round.png");
        $(this).children(1).children(0).attr("src","../approvalImg/choice_round.png");
        var option_val = $(this).children(0).html();
        var index = $(this).attr("index");
        $(_single_this).children(1).children(0).val(option_val);
        $(_single_this).attr("had_options",option_val);

        $(".popup_similar").remove();
        $(".call_back").hide();
        //默认审批人
        if(localApprovals.length>0){
            var component_id0 = localApprovals[0].approval_temp_component_id;
            if(component_id==component_id0){
                for(var d2 in localApprovals){
                    var option_index = localApprovals[d2].option_index;
                    if(option_index==index){
                        $('.copy_me_person_bigest').remove();
                        //添加默认联系人
                        addDefaultApproval(localApprovals[d2].approvers,localApprovals[d2].approverList);
                        return;
                    }else{
                        $('.copy_me_person_bigest').remove();
                    }
                }
            }
        }


        //页面可滚
        $('.body_bgcolor').css('overflow','scroll');

    });

    //点击弹出 多选框
    var _mutil_this;
    $(document).on('click','.multi_choice',function(){
        _mutil_this = $(this);
        var options_str = $(this).attr("options");
        var options_arr = [];
        options_arr = options_str.split(",");
        $(".more_again").append("<div class='popup_similar'>" +
            "<div class='real_popup_content_multi' choice_or_not=''>"+
            "<div class='option_content col-xs-9'>请选择</div>" +
            "</div></div>");
        for(var i=0;i<options_arr.length;i++){
            $(".more_again").append("<div class='popup_similar'>" +
                "<div class='real_popup_content_multi' choice_or_not='0'>"+
                "<div class='option_content col-xs-9' style='line-height: 5vw'>"+options_arr[i]+"</div>" +
                "<div class='col-xs-3'><img src='../approvalImg/unchoice_round.png' class='choice_round_img'></div>"+
                "</div></div>");
        }
        var had_options = $(this).attr("had_options");
        if(had_options!=undefined){
            if(had_options.length!=0){
                option_arr = had_options.split(",");
                var had_options_arr=[];
                had_options_arr = had_options.split(",");
                $(".option_content").each(function(){
                    for(key in had_options_arr) {
                        if (had_options_arr[key] == $(this).html()) {
                            $(this).parent().attr("choice_or_not","1");
                            $(this).next().children(0).attr("src","../approvalImg/choice_round.png");
                        }
                    }
                });
            }
        }
        $(".more_again").append("<div class='popup_similar'><div class='col-xs-6 choice_it cancel' style='border-right: 1px solid #e5e5e5'>取消</div><div class='col-xs-6 choice_it sure'>确定</div></div>");

        var cellWhole  = 7.8125 * (options_arr.length + 2);
        if(cellWhole>52){
            $(".more_again").css("marginTop",'23.95vh');
        }else{
            var top        = (100 - cellWhole)/2 + "vh";
            $(".more_again").css("marginTop",top);
        }
        $(".call_back").show();

        //页面不可滚
        $('.body_bgcolor').css('overflow','hidden');
    });
    //----点击取消
    $(document).on('click','.cancel',function(){
        $(".popup_similar").remove();
        $(".call_back").hide();
        //页面可滚
        $('.body_bgcolor').css('overflow','scroll');
    });
    //----点击选项
    $(document).on('click','.real_popup_content_multi',function(){
        var choice_or_not = $(this).attr("choice_or_not");
        var option_val = $(this).children(0).html();
        if(choice_or_not!=""){
            if(choice_or_not=="0"){
                $(this).children(1).children(0).attr("src","../approvalImg/choice_round.png");
                $(this).attr("choice_or_not","1");
                option_arr.push(option_val);
            }else{
                $(this).children(1).children(0).attr("src","../approvalImg/unchoice_round.png");
                $(this).attr("choice_or_not","0");
                for(key in option_arr){
                    if(option_arr[key]==option_val){
                        option_arr.splice(key,1);
                    }
                }
            }
        }
    });
    //--点击确定
    $(document).on('click','.sure',function(){
        //移除之前的选项
        $(_mutil_this).nextAll().remove();
        if(option_arr.length>0){
            option_str = option_arr.join(",");
            $(_mutil_this).attr("had_options",option_str);
            for(var i=0;i<option_arr.length;i++){
                if(i==0){
                    $($(_mutil_this).find('.multi_choice_val')).val(option_arr[i]);
                    //$(".multi_choice_val").val(option_arr[i]);
                }else{
                    $(_mutil_this).parent().append("<div class='options_big'>"+option_arr[i]+"</div>");
                    //$(".multi_bigest").append("<div class='options_big'>"+option_arr[i]+"</div>");
                }
            }
        }else{
            $(_mutil_this).removeAttr("had_options");
            $(_mutil_this).children(1).children(0).val($(_mutil_this).attr("data_primary"));
        }
        $(".popup_similar").remove();
        $(".call_back").hide();
        option_arr=[];
        option_str="";

        //页面可滚
        $('.body_bgcolor').css('overflow','scroll');
    });



    //提交 填写好的模板
    $("#commit_btn").on('click',function(){

        var default_value;
        var is_necessary;
        var components_arr  =[];
        var img_arr         =[];
        var file_arr        =[];
        var val_arr         =[];     //将必填的控件的值  存入
        var start_stop      ="0";
        var is_empty = false;
        //模板填写的内容
        $(".default_value").each(function(index){

            var title = $(this).attr("title");              //获取 组件的标题
            var name = $(this).attr("name");                //控件
            var interval = $(this).attr("interval");        //时间区间
            is_necessary = $(this).attr("necessary");       //是否必要
            //时间--开始
            var component_id = $(this).attr("component_id");
            if(name=="time_component"){
                if($(this).val()=="请选择"||$(this).val()=="请选择(必填)"){
                    default_value = "";
                }else{
                    initTimestamp(HTMLEncode($(this).val()));
                    default_value = timestamp;
                }
            }else if(name=="img"){


                $($(".default_value[component_id='"+ component_id +"']").find(".detail_approval_date_pic")).each(function(index){
                    //.find(".")

                    //console.log($(this).attr("class"));
                    img_arr[index]=$(this).attr("src");
                });
                default_value = img_arr.join(",");
                img_arr = [];
            }else if(name=="file"){
                $($(this).find(".file_name")).each(function(index){
                    file_arr[index]=$(this).attr("data-src");
                });
                default_value = file_arr.join(",");
                file_arr = [];
            }else if(name=="option"){
                if($(this).val()=="请选择"||$(this).val()=="请选择(必填)"){
                    default_value = "";
                }else{
                    default_value = $(this).parent().parent().attr("had_options");
                }
            }else{

                //console.log($(this).is("textarea"));


                //if ($(this).is("textare") == true){
                //    default_value = HTMLEncode($(this).html());
                //}else {
                    default_value = HTMLEncode($(this).val());
                //}

                //debugger;

                //console.log(default_value);
            }

            //时间结束
            var stop_time = HTMLEncode($(this).parent().parent().next().children(1).children().val());
            var stop_title = $(this).parent().parent().next().children(1).children().attr("title");
            var extra_value;
            if(interval=="interval"){
                if(stop_time=="请选择(必填)"){
                    $(".call_back_success").html(""+stop_title+"不能为空").show().fadeOut(2000);
                    extra_value = "";
                    val_arr.push(extra_value);

                    is_empty = true;
                    return false;
                }else{
                    initTimestamp(stop_time);
                    extra_value = timestamp;
                    val_arr.push(extra_value);
                }

                if(stop_time=="请选择"){
                    extra_value="";
                }else{
                    initTimestamp(stop_time);
                    extra_value = timestamp;
                }
            }else{
                extra_value = "";
            }

            if(extra_value!=""){
                if(extra_value<default_value){
                    start_stop = "1";
                }
            }

            if(is_necessary=="1"){
                if(name=="time_component"){
                    if($(this).val()=="请选择(必填)"){
                        $(".call_back_success").html(""+title+"不能为空").show().fadeOut(2000);
                        val_arr.push(HTMLEncode($(this).val()));

                        is_empty = true;
                        return false;
                    }else{
                        initTimestamp(HTMLEncode($(this).val()));
                        val_arr.push(timestamp);
                    }
                }else if(name=="option"){
                    if($(this).val()=="请选择(必填)"){
                        $(".call_back_success").html(""+title+"不能为空").show().fadeOut(2000);

                        is_empty = true;
                        return false;
                    }
                    val_arr.push(HTMLEncode($(this).val()));
                }else if(name=="img"){
                    //if($(".pic_one").length==0){
                    if(default_value.length == 0){
                        $(".call_back_success").html(""+title+"不能为空").show().fadeOut(2000);

                        is_empty = true;
                        return false;
                    }
                    //val_arr.push(img_arr.join(","));
                    val_arr.push(default_value);
                }else if(name=="file"){
                    //if($(".file_real").length==0){
                    if(default_value.length == 0){
                        $(".call_back_success").html(""+title+"不能为空").show().fadeOut(2000);

                        is_empty = true;
                        return false;
                    }
                    //val_arr.push(file_arr.join(","));
                    val_arr.push(default_value);
                }else{
                    if($(this).val()==""){
                        $(".call_back_success").html(""+title+"不能为空").show().fadeOut(2000);

                        is_empty = true;
                        return false;
                    }
                    val_arr.push(HTMLEncode($(this).val()));
                }
            }


            //明细
            



            //child_tag
            var child_tag;
            if($(this).parents(".detail_real").attr("class")=="detail_real"){
                child_tag = $(this).parents(".detail_real").attr("child_tag");
            }else{
                child_tag = $(this).attr("child_tag");
            }

            components_arr[index]={
                approval_temp_component_id:$(this).attr("component_id"),
                default_value:default_value,
                extra_value:extra_value,
                child_tag:child_tag
            }
        });

        if (is_empty == true){
            components_arr = [];
            return;
        }

        //审批人
        var approval_arr = [];
        var approval_person;
        $(".approval_me_name").each(function(index){
            approval_arr[index] = $(this).attr("id");
        });
        approval_person = approval_arr.join(",");

        //抄送人
        var copy_arr = [];
        var followers;
        $(".cope_me_name").each(function(index){
            copy_arr[index] = $(this).attr("id");
        });
        followers = copy_arr.join(",");



        var data = {
            approval_temp_id:""+approval_temp_id+"",
            group_id:group_id,
            user_id:user_id,
            followers:followers,
            approvers:approval_person,
            components:components_arr
        };
        var data_json = JSON.stringify(data);

        //if($.inArray("",val_arr)>-1||$.inArray("请选择(必填)",val_arr)>-1){
        //
        //    //console.log()
        //    debugger;
        //
        //}

        //debugger;
        if(start_stop=="1"){
            $(".call_back_success").html("开始时间不能大于结束时间").show().fadeOut(2000);
            return;
        }else{
            if(approval_person==""){
                $(".call_back_success").html("审批人不能为空").show().fadeOut(2000);
            }else{
                //console.log(components_arr);
                $.ajax({
                    beforeSend:function(){
                        $("#commit_btn").val("正在提交...");
                    },
                    url:apiurl+"/approvals",
                    type:"POST",
                    data:{
                        jsonString:data_json,
                        user_name:localStorage.user_name,
                        userId:localStorage.user_id,
                        token:localStorage.token,
                        imtoken:localStorage.imToken,
                        qyxBindId:localStorage.qyxBindId,
                        title:localStorage.user_name+"创建了一个审批:"+title
                    },
                    success:function(d){
                        //console.log(d);
                        if(typeof d == "object"){
                            var msg= d.msg;
                            if(msg=="202") {
                                $(".token_iframe").fadeIn(1000);
                            }
                        }
                        else
                        {
                            var data = JSON.parse(d);
                            if(data.code=="0"){
                                $(".call_back_success").html("提交成功");
                            }else{
                                $(".call_back_success").html(data.msg);
                            }
                            $(".call_back_success").fadeIn(1000,function(){
                                window.location.href="approvalDetail.html?index=2&id="+data.data+"";
                            });
                        }
                    }
                });
            }

        }
    });


    //数字金额转换成大写
    function convertCurrency(currencyDigits) {

        var MAXIMUM_NUMBER = 99999999999.99;

        var CN_ZERO = "零";
        var CN_ONE = "壹";
        var CN_TWO = "贰";
        var CN_THREE = "叁";
        var CN_FOUR = "肆";
        var CN_FIVE = "伍";
        var CN_SIX = "陆";
        var CN_SEVEN = "柒";
        var CN_EIGHT = "捌";
        var CN_NINE = "玖";
        var CN_TEN = "拾";
        var CN_HUNDRED = "佰";
        var CN_THOUSAND = "仟";
        var CN_TEN_THOUSAND = "万";
        var CN_HUNDRED_MILLION = "亿";
        var CN_DOLLAR = "元";
        var CN_TEN_CENT = "角";
        var CN_CENT = "分";
        var CN_INTEGER = "整";


        var integral;
        var decimal;
        var outputCharacters;
        var parts;
        var digits, radices, bigRadices, decimals;
        var zeroCount;
        var i, p, d;
        var quotient, modulus;


        currencyDigits = currencyDigits.toString();
        if (currencyDigits == "") {
            outputCharacters="";
            return "";
        }


        currencyDigits = currencyDigits.replace(/,/g, "");
        currencyDigits = currencyDigits.replace(/^0+/, "");

        if (Number(currencyDigits) > MAXIMUM_NUMBER) {
            $(".call_back_success").html("输入金额过大").show().fadeOut(2000);
            return "";
        }


        parts = currencyDigits.split(".");
        if (parts.length > 1) {
            integral = parts[0];
            decimal = parts[1];

            decimal = decimal.substr(0, 2);
        }
        else {
            integral = parts[0];
            decimal = "";
        }

        digits = [CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, CN_NINE];
        radices = ["", CN_TEN, CN_HUNDRED, CN_THOUSAND];
        bigRadices = ["", CN_TEN_THOUSAND, CN_HUNDRED_MILLION];
        decimals = [CN_TEN_CENT, CN_CENT];

        outputCharacters = "";

        if (Number(integral) > 0) {
            zeroCount = 0;
            for (i = 0; i < integral.length; i++) {
                p = integral.length - i - 1;
                d = integral.substr(i, 1);
                quotient = p / 4;
                modulus = p % 4;
                if (d == "0") {
                    zeroCount++;
                }
                else {
                    if (zeroCount > 0)
                    {
                        outputCharacters += digits[0];
                    }
                    zeroCount = 0;
                    outputCharacters += digits[Number(d)] + radices[modulus];
                }
                if (modulus == 0 && zeroCount < 4) {
                    outputCharacters += bigRadices[quotient];
                }
            }
            outputCharacters += CN_DOLLAR;
        }

        if (decimal != "") {
            for (i = 0; i < decimal.length; i++) {
                d = decimal.substr(i, 1);
                if (d != "0") {
                    outputCharacters += digits[Number(d)] + decimals[i];
                }
            }
        }

        if (outputCharacters == "") {
            outputCharacters = CN_ZERO + CN_DOLLAR;
        }
        if (decimal == "") {
            outputCharacters += CN_INTEGER;
        }
        return outputCharacters;
    }




    //联系人的js
    //点击 添加-审批人-抄送人
    getTeamName();
    var top = 0;


    $(document).on('click','#add_approval_person',function(){
        //记录当前坐标

        var content = document.getElementsByClassName('down_navbar_div');
        //top = content[0].offsetTop;
        top = $(document).scrollTop();
        //console.log("top:"+ top);

        approval_copy = "0";
        $(".model_div").hide();
        $(".contact_div").show();
        initpart();
    });

    $(document).on('click','#add_copy_person',function(){
        //记录当前坐标
        var content = document.getElementsByClassName('down_navbar_div');
        top = $(document).scrollTop();
        //console.log("top:"+ top);

        approval_copy = "1";
        $(".model_div").hide();
        $(".contact_div").show();
        initpart();
    });
    //-----点击头像删除此人
    $(document).on('click','.cope_me_cover',function(){
        var id      = $(this).parent().children(":last-child").attr("id");
        var name    = $(this).next().attr("name");
        var avatar  = $(this).next().attr("avatar");
        var qyxBindId = $(this).next().attr("qyxBindId");

        //debugger;
        if(localApprovals.length>0){
            $('.call_back_success').html("默认审批人,无法删除").show().fadeOut(2000);
        }else{
            $(this).parent().parent().remove();
            for(key in contact_arr){
                if(contact_arr[key]==id){
                    contact_arr.splice(key,1);
                    contact_name_arr.splice(key,1);
                    contact_avatar_arr.splice(key,1);
                    contact_qyxBindId_arr.splice(key,1);
                }
            }
        }
    });
    $(document).on('click','.cope_me_cover1',function(){
        $(this).parent().parent().remove();
        var id      = $(this).parent().children(":last-child").attr("id");
        var name    = $(this).next().attr("name");
        var avatar  = $(this).next().attr("avatar");
        var qyxBindId = $(this).next().attr("qyxBindId");
        for(key in contact_arr1){
            if(contact_arr1[key]==id){
                contact_arr1.splice(key,1);
                contact_name_arr1.splice(key,1);
                contact_avatar_arr1.splice(key,1);
                contact_qyxBindId_arr1.splice(key,1);
            }
        }
    });

    //点击联系人的返回按钮
    $(".contact_back").on('click',function(){
        $(".contact_div").hide();
        $(".model_div").show();
        $(".team_bigest").remove();
        $(".user_mid").remove();
        $(".group_name_div").remove();
        if(approval_copy=="0"){
            for(a1 in temp_arr){
                for(a in contact_arr){
                    if(contact_arr[a]==temp_arr[a1]){
                        contact_arr.splice(a,1);
                    }
                }
            }
            for(b1 in temp_name_arr){
                for(b in contact_name_arr){
                    if(contact_name_arr[b]==temp_name_arr[b1]){
                        contact_name_arr.splice(b,1);
                    }
                }
            }
            for(c1 in temp_avatar_arr){
                for(c in contact_avatar_arr){
                    if(contact_avatar_arr[c]==temp_avatar_arr[c1]){
                        contact_avatar_arr.splice(c,1);
                    }
                }
            }
            for(d1 in temp_qyxBindId_arr){
                for(d in contact_qyxBindId_arr){
                    if(contact_qyxBindId_arr[d]==temp_qyxBindId_arr[d1]){
                        contact_qyxBindId_arr.splice(d,1);
                    }
                }
            }
        }
        else{
            for(a1 in temp_arr){
                for(a in contact_arr1){
                    if(contact_arr1[a]==temp_arr[a1]){
                        contact_arr1.splice(a,1);
                    }
                }
            }
            for(b1 in temp_name_arr){
                for(b in contact_name_arr1){
                    if(contact_name_arr1[b]==contact_name_arr1[b1]){
                        contact_name_arr1.splice(b,1);
                    }
                }
            }
            for(c1 in temp_avatar_arr){
                for(c in contact_avatar_arr1){
                    if(contact_avatar_arr1[c]==temp_avatar_arr[c1]){
                        contact_avatar_arr1.splice(c,1);
                    }
                }
            }
            for(d1 in temp_qyxBindId_arr){
                for(d in contact_qyxBindId_arr1){
                    if(contact_qyxBindId_arr1[d]==temp_qyxBindId_arr[d1]){
                        contact_qyxBindId_arr1.splice(d,1);
                    }
                }
            }
        }
        temp_arr            =[];
        temp_name_arr       =[];
        temp_avatar_arr     =[];
        temp_qyxBindId_arr  =[];

        //坐标归位
        window.scrollTo(0,top);
        top = 0;
    });
    //获取所在团队的名称
    function getTeamName(){
        var url_c  = tk_apiurl+"contacteam/findone";
        var data = {"userId":user_id,"token":token,"data":JSON.stringify({'id':group_id})};
        $.ajax({
            async: false,
            crossDomain: true,
            url: url_c,
            method: "POST",
            data:data,
            jsonpCallback:"jsoncallback",
            dataType: "jsonp",
            success:function(d) {
                var data1 = '';
                var status = '';

                data = eval('(' + d + ')');
                status = data.statusCode;
                if (data.result) {
                    data1 = eval('(' + data.result + ')');
                }

                teamName = data1.teamName;
            }
        });
    }
    //获取团队下的部门列表
    function initpart(){
        var url_c  = tk_apiurl+"contacteam/mydepts";
        var data = {"userId":user_id,"token":token,"data":JSON.stringify({'teamId':localStorage.group_id,'parentId':"0"})};
        $.ajax({
            beforeSend:function(){
                $(".loading_c").show();
                $(".contact_bigest").hide();
            },
            async: true,
            crossDomain: true,
            url: url_c,
            method: "POST",
            data:data,
            jsonpCallback:"jsoncallback",
            dataType: "jsonp",
            success:function(d){
                var data='';
                var data1='';
                var status='';

                data = eval('('+d+')');
                status = data.statusCode;
                if(data.result){
                    data1 = eval('(' + data.result + ')');
                }
                if(status==202){
                    $(".token_iframe").fadeIn(1000);
                }else{
                    $(".loading_c").hide();

                    //title
                    $(".contact_title").html(teamName);
                    //contact_bigest添加名称条
                    var contact_name_html = "<div class='group_name_div'>"+teamName+"<img src='../approvalImg/contact.png' class='group_img'></div>";
                    $(".contact_bigest").show().prepend(contact_name_html);
                    //加载部门
                    var team = data1.depts;
                    for(var i=0;i<team.length;i++){
                        var html="<div class='team_bigest' id='"+team[i].id+"'>" +
                            "<div class='team_mid' is_choice='0'>" +
                            "<div class='team_left'>" +
                            //"<img src='../../approval/approvalImg/team.png' class='team_pic'>" +
                            "<div class='team_name'>"+team[i].departmentName+"</div>" +
                            "</div>" +
                            "<div class='team_right'>" +
                            "<img src='../../log/logImg/rightIcon.png' class='right_icon'></div></div>" +
                            "</div>";
                        $(".team_content_bigest").append(html);
                    }
                    $(".team_mid").each(function(){
                        $(this).last().css('borderBottom','0px');
                    });

                    //加载默认的用户
                    var users = data1.users;
                    var html_user="";
                    for(var a=0;a<users.length;a++){
                        //var _choice = "0";
                        //var _img    = "<img src='../../log/logImg/tick.png' class='tick_icon'>";
                        //if(approval_copy=="0"){
                        //    for(var b=0;b<contact_arr.length;b++){
                        //        if(contact_arr[b]==users[a].userId){
                        //            _choice = "1";
                        //            _img    = "<img src='../../log/logImg/tick.png' class='tick_icon' style='display: block'>";
                        //        }
                        //    }
                        //}else{
                        //    for(var z=0;z<contact_arr1.length;z++){
                        //        if(contact_arr1[z]==users[a].userId){
                        //            _choice = "1";
                        //            _img    = "<img src='../../log/logImg/tick.png' class='tick_icon' style='display: block'>";
                        //        }
                        //    }
                        //}

                        var img_url;
                        var avatar1 = users[a].avatar;
                        var qyxBindId = users[a].userIM;
                        var name = users[a].userName;

                        //debugger;




                        //if(avatar1==""){
                            var color = avatar_getColor(qyxBindId);
                            img_url = "<div class='user_pic_div' style='background-color: "+color+"'>"+avatar_name(name)+"</div>";
                        //}else{
                        if (avatar1.length > 0){
                            var src = avatar_getUrl(localStorage.user_id,localStorage.token,avatar1);
                            img_url += "<img src='"+src+"' class='user_pic' hidden>";
                        }

                        //}

                        //html_user +="<div class='user_mid' id='"+users[a].userId+"' qyxBindId='"+qyxBindId+"' name='"+users[a].userName+"' avatar='"+users[a].avatar+"' is_choice='"+_choice+"'>" +
                        html_user +="<div class='user_mid' id='"+users[a].userId+"' qyxBindId='"+qyxBindId+"' name='"+users[a].userName+"' avatar='"+users[a].avatar+"'>" +
                            "<div class='user_left'>" +
                            ""+img_url+"" +
                            "<div class='user_name'>"+users[a].userName+"</div>" +
                            "</div>" +
                            "<div class='user_right'>" +
                            "</div></div>";
                    }
                    $(".contact_content").append(html_user);


                    showAvatar(".user_pic");
                }
            }
        });
    }
    //点击行获取部门下的成员列表

    var _team;
    $(document).on('click','.team_mid',function(){
        $(this).css("borderBottom","1px solid #e5e5e5");
        _team = $(this).parent();
        var is_choice = $(this).attr("is_choice");
        if(is_choice=="0"){
            $(".right_icon").addClass('right_icon_down').attr('src','../../task/images/task/arrow.png');
            var deptId = $(_team).attr("id");
            var url    = tk_apiurl+"contacteam/mydeptsall";
            var data   = {"userId":user_id,"token":token,"data":JSON.stringify({'teamId':group_id,'deptId':deptId})};
            $.ajax({
                async: true,
                crossDomain: true,
                url: url,
                method: "POST",
                data:data,
                jsonpCallback:"jsoncallback",
                dataType: "jsonp",
                success:function(d){
                    var data='';
                    var data1='';
                    var status='';

                    data   = eval('('+d+')');
                    status = data.statusCode;
                    if(data.result){
                        data1 = eval('(' + data.result + ')');
                    }
                    if(status==202){
                        $(".token_iframe").fadeIn(1000);
                    }
                    else {
                        var users = data1.users;

                        var html="";
                        for(var i=0;i<users.length;i++){
                            //var _choice = "0";
                            //var _img    = "<img src='../../log/logImg/tick.png' class='tick_icon'>";
                            //if(approval_copy=="0"){
                            //    for(var j=0;j<contact_arr.length;j++){
                            //        if(contact_arr[j]==users[i].userId){
                            //            _choice = "1";
                            //            _img    = "<img src='../../log/logImg/tick.png' class='tick_icon' style='display: block'>";
                            //        }
                            //    }
                            //}else{
                            //    for(var z=0;z<contact_arr1.length;z++){
                            //        if(contact_arr1[z]==users[i].userId){
                            //            _choice = "1";
                            //            _img    = "<img src='../../log/logImg/tick.png' class='tick_icon' style='display: block'>";
                            //        }
                            //    }
                            //}

                            var img_url;
                            var avatar1 = users[i].avatar;
                            var qyxBindId = users[i].userIM;
                            var name = users[i].userName;



                            //if(avatar1==""){
                                var color = avatar_getColor(qyxBindId);
                                img_url = "<div class='user_pic_div' style='background-color: "+color+"'>"+avatar_name(name)+"</div>";
                            if (avatar1.length > 0){
                                var src = avatar_getUrl(localStorage.user_id,localStorage.token,avatar1);
                                img_url += "<img src='"+src+"' class='user_pic' hidden>";
                            }
                            //}else{
                            //    var src = avatar_getUrl(localStorage.user_id,localStorage.token,avatar1);
                            //    img_url = "<img src='"+src+"' class='user_pic'>";
                            //}

                            //html +="<div class='user_mid' id='"+users[i].userId+"' qyxBindId='"+qyxBindId+"' name='"+users[i].userName+"' avatar='"+users[i].avatar+"' is_choice='"+_choice+"'>" +
                            html +="<div class='user_mid' id='"+users[i].userId+"' qyxBindId='"+qyxBindId+"' name='"+users[i].userName+"' avatar='"+users[i].avatar+"'>" +
                                "<div class='user_left'>" +
                                ""+img_url+"" +
                                "<div class='user_name'>"+users[i].userName+"</div>" +
                                "</div>" +
                                "<div class='user_right'>" +
                                "</div></div>";
                        }
                        $(_team).append(html);

                        $(".user_mid").last().css("border","none");

                        showAvatar(".user_pic");
                    }
                }
            });
            $(this).attr("is_choice","1");
        }else{
            $(".right_icon").removeClass('right_icon_down').attr('src','../../log/logImg/rightIcon.png');
            $(this).nextAll().hide();
            $(this).attr("is_choice","0");
        }
    });

    //选择联系人
    $(document).on('click','.user_mid',function(){
        var id        = $(this).attr('id');
        var name      = $(this).attr('name');
        var avatar    = $(this).attr('avatar');
        //var is_choice = $(this).attr("is_choice");
        var qyxBindId = $(this).attr("qyxBindId");
        //隐藏联系人界面 移除联系人cell
        $(".contact_div").hide();
        $(".model_div").show();
        $(".team_bigest").remove();
        $(".user_mid").remove();
        $(".group_name_div").remove();

        //console.log(contact_arr1);

        if(contact_arr.indexOf(id)<0){
            if(approval_copy=="0"){
                contact_arr.unshift(id);
                contact_name_arr.unshift(name);
                contact_avatar_arr.unshift(avatar);
                contact_qyxBindId_arr.unshift(qyxBindId);

                $(".copy_me_person_bigest").remove();
                for(var i=0,j= 0,z= 0,x=0;i<contact_arr.length,j<contact_name_arr.length,z<contact_avatar_arr.length,x<contact_qyxBindId_arr.length;i++,j++,z++,x++){
                    var img_src;
                    //if(contact_avatar_arr[z]==""){
                        var color = avatar_getColor(contact_qyxBindId_arr[x]);
                        img_src   = "<div class='cope_me_cover' style='background-color: "+color+"'>"+avatar_name(contact_name_arr[j])+"</div>";
                    //}else{
                    if(contact_avatar_arr[z].length>0){
                        var src = avatar_getUrl(localStorage.user_id,localStorage.token,contact_avatar_arr[z]);
                        img_src += "<img src='"+src+"' class='cope_me_cover' qyxBindId='"+ contact_qyxBindId_arr[x] +"' hidden>";
                    }
                    $("#approval_person").prepend("<div class='copy_me_person_bigest'><div class='copy_me_person'>"+img_src+"<div class='approval_me_name' id='"+contact_arr[i]+"' name='"+contact_name_arr[j]+"' avatar='"+contact_avatar_arr[z]+"'>"+contact_name_arr[j]+"</div></div><div class='dot_box'></div></div>");
                }

                var height = 0;

                $(".copy_me_person_bigest").each(function(){
                    var current_height = $(this).height();
                    if (current_height > height){
                        height = current_height;
                    }
                });

                $(".copy_me_person_bigest").each(function(){
                    $(this).height(height);
                });

                showAvatar(".cope_me_cover");
            }
        }else {
            if(approval_copy=="0") {
                $(".call_back_success").html("该审批人已在列表中").fadeIn();
                setTimeout(function(){
                    $(".call_back_success").fadeOut(1000);
                },1000);
            }
        }

        if(contact_arr1.indexOf(id)<0){
            if(approval_copy=="1"){
                contact_arr1.unshift(id);
                contact_name_arr1.unshift(name);
                contact_avatar_arr1.unshift(avatar);
                contact_qyxBindId_arr1.unshift(qyxBindId);
                $(".copy_me_person_bigest1").remove();

                for(var a=0,b= 0,c= 0,d=0;a<contact_arr1.length,b<contact_name_arr1.length,c<contact_avatar_arr1.length,d<contact_qyxBindId_arr1.length;a++,b++,c++,d++){
                    var img_src1;
                    //if(contact_avatar_arr1[c]==""){
                        var color1 = avatar_getColor(contact_qyxBindId_arr1[d]);
                        img_src1   = "<div class='cope_me_cover1' style='background-color: "+color1+"'>"+avatar_name(contact_name_arr1[b])+"</div>";
                    //}else{
                    if(contact_avatar_arr1[c].length>0){
                        //debugger;
                        var src1 = avatar_getUrl(localStorage.user_id,localStorage.token,contact_avatar_arr1[c]);
                        img_src1 += "<img src='"+src1+"' class='cope_me_cover1' hidden>";
                    }
                    $("#copy_person").prepend("<div class='copy_me_person_bigest1'><div class='copy_me_person1'>"+img_src1+"<div class='cope_me_name' id='"+contact_arr1[a]+"' name='"+contact_name_arr1[b]+"' avatar='"+contact_avatar_arr1[c]+"'>"+contact_name_arr1[b]+"</div></div><div class='dot_box'></div></div>");
                }



                var height = 0;

                $(".copy_me_person_bigest1").each(function(){
                    var current_height = $(this).height();
                    if (current_height > height){
                        height = current_height;
                    }
                });

                $(".copy_me_person_bigest1").each(function(){
                    $(this).height(height);
                });

                showAvatar(".cope_me_cover1");
            }
        }else {
            if(approval_copy=="1") {
                $(".call_back_success").html("该抄送人已在列表中").fadeIn();
                setTimeout(function(){
                    $(".call_back_success").fadeOut(1000);
                },1000);
            }
        }

        //坐标归位
        window.scrollTo(0,top);
        top = 0;
    });




    function showAvatar(classname){
        $(classname).one("load",function(){
            $(this).show();
            $(this).prev().hide();
        });
    }


});
